.NET MAUI Android中Plugin.Firebase调用LogEvent触发NullReferenceException
我在.NET MAUI应用中使用Plugin.Firebase向Google Analytics(GA4)发送数据,代码如下:
if (DeviceInfo.Platform == DevicePlatform.iOS || DeviceInfo.Platform == DevicePlatform.Android) { if (AgreeToAnalytics) { var sut = CrossFirebaseAnalytics.Current; sut.LogEvent(gaEvent, parameters); } }
在Android平台调用LogEvent()方法时抛出空引用异常:
Plugin.Firebase.Analytics.FirebaseAnalyticsImplementation.LogEvent(String eventName, IDictionary`2 parameters) System.NullReferenceException: Object reference not set to an instance of an object.
相关日志信息:
10-17 13:12:33.857 10916 10916 F mono-rt : [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object. 10-17 13:12:33.857 10916 10916 F mono-rt :
at Plugin.Firebase.Analytics.FirebaseAnalyticsImplementation.LogEvent(String eventName, IDictionary`2 parameters)
我传入的parameters不为空,eventName是有效字符串,参数集合中的所有键值对也都是非空字符串。该功能此前运行正常,推测问题出在从.NET 6迁移到.NET 7的过程中,目前已向插件作者提交Issue但尚未收到回复。
内容的提问来源于stack exchange,提问作者David Shochet

