ASP.NET FirebaseAdmin无法初始化-System.MissingFieldException [英] ASP.NET FirebaseAdmin fails to initilize - System.MissingFieldException

查看:151
本文介绍了ASP.NET FirebaseAdmin无法初始化-System.MissingFieldException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET(Web API)项目,我向该项目添加了FirebaseAdmin,但是在调用方法 FirebaseMessaging m = FirebaseMessaging.GetMessaging(App);

在新的Windows Forms项目上执行相同的步骤即可正常工作,并且能够传递消息.

  FirebaseAdmin.dll中发生类型'System.MissingFieldException'的异常,但未在用户代码中处理附加信息:找不到字段:'Initializer.DefaultHandleUnsuccessfulResponseFunc'. 

使用此 sample 代码测试Firebase:

  FirebaseApp App = FirebaseApp.Create(新的AppOptions(){凭据= GoogleCredential.FromFile("/path/to/jsonfile.json"),});var registrationToken ="cKhzptf1StOPfX82HLf ...";var message = new FirebaseAdmin.Messaging.Message(){通知=新的FirebaseAdmin.Messaging.Notification(){标题=某些标题",身体=身体",},令牌= registrationToken,};//这里抛出错误FirebaseMessaging m = FirebaseMessaging.GetMessaging(App);字符串响应=等待m.SendAsync(message);Console.WriteLine(成功发送的消息:" +响应); 

解决方案

该解决方案基于Sami提到的解决方案,但是需要对其进行修改.

"DLL地狱"问题是因为GAC中的System.Net.Http.dll版本错误.该库由FirebaseAdmin的一部分Google.Apis.Auth包使用.

要修复此问题,您需要先验证您需要哪个版本.由于我可以在本地计算机上使用它,因此我将bin目录中的System.Net.Http.dll文件放入PowerShell中并启动了命令以查看版本:

 ([[system.reflection.assembly] :: loadfile("C:\ Projects \ ... \ EventNotifier \ EventNotifier \ bin \ System.Net.Http.dll")).全名 

回复是

System.Net.Http,版本= 4.0.0.0,文化=中性,PublicKeyToken = b03f5f7f11d50a3a

一旦确定了正确的版本,就需要在项目的web.config中指定此版本:

 < dependentAssembly>< assemblyIdentity name =" System.Net.Http"publicKeyToken ="b03f5f7f11d50a3a"文化=中立"/>< bindingRedirect oldVersion ="0.0.0.0-9.7.0.0"newVersion ="4.0.0.0"/></dependentAssembly> 

解决了这个问题.

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);

解决方案

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.

这篇关于ASP.NET FirebaseAdmin无法初始化-System.MissingFieldException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆