iOS端升级AppCenter至5.0.1后启动出现MSACDeviceHistoryInfo解码异常
AppCenter升级后iOS端启动异常问题
问题描述
将AppCenter从3.2.2版本升级至5.0.1版本后,iOS端以仅链接框架SDK的链接行为调用AppCenter.Start时触发异常。即使降级AppCenter版本,异常仍持续存在,只有删除设备上的应用并重新安装后,异常才会消失。尝试设置跳过链接Microsoft.AppCenter,并未解决问题。
异常堆栈信息
Foundation.MonoTouchException: Objective-C异常抛出。名称: NSInvalidUnarchiveOperationException 原因: *** -[NSKeyedUnarchiver decodeObjectForKey:]: 无法为键(NS.objects)解码类(MSACDeviceHistoryInfo)的对象,因为未找到名为"MSACDeviceHistoryInfo"的类;该类需要在源代码中定义或从库中链接(确保类属于正确的目标)。如果类已重命名,请使用setClassName:forClass:为NSKeyedUnarchiver添加类转换映射 Native堆栈跟踪: 0 CoreFoundation 0x000000010e6928ab __exceptionPreprocess + 242 1 libobjc.A.dylib 0x0000000110c68ba3 objc_exception_throw + 48 2 Foundation 0x00000001150477d9 -[NSCoder __failWithException:] + 165 3 Foundation 0x00000001150479ab -[NSCoder(Exceptions) __failWithExceptionName:errorCode:format:] + 384 4 Foundation 0x00000001150e2eb0 _decodeObjectBinary + 646 5 Foundation 0x00000001150e5662 -[NSKeyedUnarchiver _decodeArrayOfObjectsForKey:] + 1752 6 Foundation 0x00000001150273ad -[NSArray(NSArray) initWithCoder:] + 161 7 Foundation 0x00000001150e3898 _decodeObjectBinary + 3182 8 Foundation 0x00000001150e22d2 _decodeObject + 163 9 Foundation 0x00000001150e21b2 -[NSKeyedUnarchiver decodeObjectForKey:] + 162 10 Foundation 0x00000001150e1110 +[NSKeyedUnarchiver unarchiveObjectWithData:] + 79 11 MyApp.iOS 0x0000000104de107b -[MSDeviceTracker init] + 177 12 MyApp.iOS 0x0000000104de0f59 __33+[MSDeviceTracker sharedInstance]_block_invoke + 41 13 libdispatch.dylib 0x000000011ac57a3a _dispatch_client_callout + 8 14 libdispatch.dylib 0x000000011ac58db3 _dispatch_once_callout + 20 15 MyApp.iOS 0x0000000104de0f2d +[MSDeviceTracker sharedInstance] + 45 16 MyApp.iOS 0x0000000104dd0d22 +[MSAppCenter setWrapperSdk:] + 56 17 MyApp.iOS 0x0000000105362a69 xamarin_dyn_objc_msgSend + 217 18 ??? 0x000000015c3c67ec 0x0 + 5842429932 at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Library/Frameworks/i/Versions/16.1.1.27/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:460 at ObjCRuntime.Runtime.throw_ns_exception (System.IntPtr exc) [0x00000] in /Users/builder/azdo/_work/2/s/xamarin-macios/runtime/Delegates.generated.cs:398 at (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr) at (wrapper managed-to-native) ApiDefinition.Messaging.void_objc_msgSend_IntPtr(intptr,intptr,intptr) at Microsoft.AppCenter.iOS.Bindings.MSAppCenter.SetWrapperSdk (Microsoft.AppCenter.iOS.Bindings.MSWrapperSdk wrapperSdk) [0x00023] in <d384bd2ae92b44008630788986ca7bdf>:0 at Microsoft.AppCenter.AppCenter.SetWrapperSdk () [0x00017] in <df2ccd8a0b774ab79c869a1d3fbc3ad1>:0 at Microsoft.AppCenter.AppCenter.PlatformStart (System.String appSecret, System.Type[] services) [0x00000] in <df2ccd8a0b774ab79c869a1d3fbc3ad1>:0 at Microsoft.AppCenter.AppCenter.Start (System.String appSecret, System.Type[] services) [0x00000] in <df2ccd8a0b774ab79c869a1d3fbc3ad1>:0 at MyApp.App.OnStart () [0x00006] in /Users/username/Documents/GitHub/MyApp/MyApp/App.xaml.cs:112 at Xamarin.Forms.Application.SendStart () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Application.cs:346 at Xamarin.Forms.Platform.iOS.FormsApplicationDelegate.FinishedLaunching (UIKit.UIApplication uiApplication, Foundation.NSDictionary launchOptions) [0x00036] in D:\a\1\s\Xamarin.Forms.Platform.iOS\FormsApplicationDelegate.cs:58 at MyApp.iOS.Core.AppDelegate.FinishedLaunching (UIKit.UIApplication nativeApp, Foundation.NSDictionary options) [0x000e4] in /Users/username/Documents/GitHub/MyApp/iOS/Core/AppDelegate.cs:100 at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,string[],intptr,intptr,intptr&) at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.1.1.27/src/Xamarin.iOS/UIKit/UIApplication.cs:57 at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.1.1.27/src/Xamarin.iOS/UIKit/UIApplication.cs:92 at MyApp.iOS.Application.Main (System.String[] args) [0x00000] in /Users/username/Documents/GitHub/MyApp/iOS/Main.cs:13
解决方案建议
- 清理旧缓存数据:异常根源是AppCenter升级后,旧版本存储的
MSACDeviceHistoryInfo对象无法被新版本解码。可在AppCenter.Start调用前手动清理相关存储:var cacheDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "com.microsoft.appcenter"); if (Directory.Exists(cacheDir)) { Directory.Delete(cacheDir, true); } - 调整链接行为:将iOS项目的链接行为从仅链接框架SDK改为不链接,测试是否解决问题后,再逐步优化链接配置,确保
MSACDeviceHistoryInfo类被正确链接。 - 添加类映射:在App启动时(如
AppDelegate.FinishedLaunching中)添加NSKeyedUnarchiver的类映射,兼容旧版本类名:NSKeyedUnarchiver.SetClassName("MSACDeviceHistoryInfo", typeof(MSACDeviceHistoryInfo)); - 强制刷新依赖:清理NuGet缓存并重新安装AppCenter包,确保依赖文件完整:
之后重新还原项目依赖。nuget locals all -clear
内容的提问来源于stack exchange,提问作者Bohdan
相关产品推荐
相关产品推荐

