问题
I have an ASP.NET ( Web API ) project, I added FirebaseAdmin to the project but it fails to initialize when calling the method FirebaseMessaging m = FirebaseMessaging.GetMessaging(App);
Same steps on a new Windows Forms project work just fine, and was able to deliver the message.
An exception of type 'System.MissingFieldException' occurred in FirebaseAdmin.dll but was not handled in user code
Additional information: Field not found: 'Initializer.DefaultHandleUnsuccessfulResponseFunc'.
Used this sample code to test Firebase:
FirebaseApp App = FirebaseApp.Create(new AppOptions()
{
Credential = GoogleCredential.FromFile("/path/to/jsonfile.json"),
});
var registrationToken = "cKhzptf1StOPfX82HLf...";
var message = new FirebaseAdmin.Messaging.Message()
{
Notification = new FirebaseAdmin.Messaging.Notification()
{
Title = "Some title",
Body = "A body",
},
Token = registrationToken,
};
// Error is thrown here
FirebaseMessaging m = FirebaseMessaging.GetMessaging(App);
string response = await m.SendAsync(message);
Console.WriteLine("Successfully sent message: " + response);
回答1:
The solution is basing on the one mentioned by Sami, however it was needed to modify it.
The "DLL Hell" problem is because there is wrong version of System.Net.Http.dll located in GAC. That library was used by Google.Apis.Auth package which is part of FirebaseAdmin.
To make it fixed you need to verify first which version do you need. Since i have it working on local machine, I took the System.Net.Http.dll file in my bin directory and started command in PowerShell to see the version:
([system.reflection.assembly]::loadfile("C:\Projects\...\EventNotifier\EventNotifier\bin\System.Net.Http.dll")).FullName
The response was
System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
Once proper version identified, it's needed to specify this version in the web.config of the project:
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.7.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
That fixed the issue.
回答2:
Removing this dependency from Web.config
fixes the issue, but I can't understand why
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.1.1.3" newVersion="4.1.1.3" />
</dependentAssembly>
来源:https://stackoverflow.com/questions/65698676/asp-net-firebaseadmin-fails-to-initilize-system-missingfieldexception