本机 Xamarin.Android 应用程序在发布模式下不断崩溃
Native Xamarin.Android app keeps crashing in release mode
我有一个本机 Xamarin.Android 应用程序是我几年前开发的,从那时起我就一直在维护它。最近,我尝试构建一个新版本,但该应用程序一直崩溃。我过去使用相同的项目和编译设置发布了数十个版本。这是我在发行版中获得的堆栈跟踪示例:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies.
[mono-rt] at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction10-21 13:24:49.970 F/mono-rt (15785): File name: 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e'
[mono-rt] at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in :0
[mono-rt] at Java.Interop.JniEnvironment+c.b__35_0 () [0x00000] in :0
[mono-rt] at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in :0
[mono-rt] at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in :0
[mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in :0ds.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0002d] in :0
[mono-rt] at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeObjectMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in :0
[mono-rt] at Java.Interop.JniEnvironment+StaticMet10-21 13:24:49.970 F/mono-rt (15785): at Android.OS.Looper.get_MainLooper () [0x0000a] in :0
[mono-rt] at Android.Runtime.AndroidEnvironment.GetDefaultSyncContext () [0x00000] in :0
[mono-rt] at System.AndroidPlatform.GetDefaultSyncContext () [0x00000] in :0
[mono-rt] at System.Threading.SynchronizationContext.GetThreadLocalContext () [0x00005] in :0
[mono-rt] at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task ignored, System.Boolean canInlineContinuationTask) [0x00003] in :0
[mono-rt] at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0
[mono-rt] at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x0004f] in :0
[mono-rt] at System.Threading.Tasks.TaskFactory`1+c__DisplayClass38_0`1[TResult,TArg1].b__0 (System.IAsyncResult iar) [0x00008] in :0
[mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in 10-21 13:24:49.970 F/mono-rt (15785): at (wrapper managed-to-native) System.Runtime.Remoting.Messaging.AsyncResult.Invoke(System.Runtime.Remoting.Messaging.AsyncResult)
[mono-rt] at System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in :0
[mono-rt] at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in :0
从堆栈跟踪中,我感觉这可能是 linker 的问题,但我已经尝试了所有 3 个设置(不要 link、link仅 SDK 程序集,link 全部)。当在这里和那里更改一些代码时,有时堆栈跟踪会略有不同,但没有什么真正有用的。这是我正在使用的编译设置:
应用程序有时会成功启动而无需随时更改。它只会工作一次。
我错过了什么?
确保您的 .NET 框架已打补丁。 Microsoft 发布了 .NET 补丁以允许可移植 Class 库正确找到合适的运行时 (KB2468871)。如果您看到上述异常(或类似异常),则表示您缺少最新的 .NET 框架补丁。
我很确定你在发行版中有一些奇怪的行为。由于您在 android 上使用单声道,因此您可以在 return 某处调用 await 函数 Task<T>
您不能使用 await 而是 .GetAwaiter().Result.
我有一个本机 Xamarin.Android 应用程序是我几年前开发的,从那时起我就一直在维护它。最近,我尝试构建一个新版本,但该应用程序一直崩溃。我过去使用相同的项目和编译设置发布了数十个版本。这是我在发行版中获得的堆栈跟踪示例:
[mono-rt] [ERROR] FATAL UNHANDLED EXCEPTION: System.IO.FileNotFoundException: Could not load file or assembly 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. [mono-rt] at System.Threading.Tasks.TaskFactory`1[TResult].FromAsyncCoreLogic (System.IAsyncResult iar, System.Func`2[T,TResult] endFunction, System.Action`1[T] endAction10-21 13:24:49.970 F/mono-rt (15785): File name: 'System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' [mono-rt] at Java.Interop.JniEnvironmentInfo..ctor () [0x00006] in :0 [mono-rt] at Java.Interop.JniEnvironment+c.b__35_0 () [0x00000] in :0 [mono-rt] at System.Threading.ThreadLocal`1[T].GetValueSlow () [0x00031] in :0 [mono-rt] at System.Threading.ThreadLocal`1[T].get_Value () [0x0003e] in :0 [mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in :0ds.CallStaticObjectMethod (Java.Interop.JniObjectReference type, Java.Interop.JniMethodInfo method, Java.Interop.JniArgumentValue* args) [0x0002d] in :0 [mono-rt] at Java.Interop.JniPeerMembers+JniStaticMethods.InvokeObjectMethod (System.String encodedMember, Java.Interop.JniArgumentValue* parameters) [0x00018] in :0 [mono-rt] at Java.Interop.JniEnvironment+StaticMet10-21 13:24:49.970 F/mono-rt (15785): at Android.OS.Looper.get_MainLooper () [0x0000a] in :0 [mono-rt] at Android.Runtime.AndroidEnvironment.GetDefaultSyncContext () [0x00000] in :0 [mono-rt] at System.AndroidPlatform.GetDefaultSyncContext () [0x00000] in :0 [mono-rt] at System.Threading.SynchronizationContext.GetThreadLocalContext () [0x00005] in :0 [mono-rt] at System.Threading.Tasks.SynchronizationContextAwaitTaskContinuation.Run (System.Threading.Tasks.Task ignored, System.Boolean canInlineContinuationTask) [0x00003] in :0 [mono-rt] at System.Threading.Tasks.Task.FinishStageThree () [0x0003c] in :0 [mono-rt] at System.Threading.Tasks.Task`1[TResult].TrySetResult (TResult result) [0x0004f] in :0 [mono-rt] at System.Threading.Tasks.TaskFactory`1+c__DisplayClass38_0`1[TResult,TArg1].b__0 (System.IAsyncResult iar) [0x00008] in :0 [mono-rt] at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00000] in 10-21 13:24:49.970 F/mono-rt (15785): at (wrapper managed-to-native) System.Runtime.Remoting.Messaging.AsyncResult.Invoke(System.Runtime.Remoting.Messaging.AsyncResult) [mono-rt] at System.Runtime.Remoting.Messaging.AsyncResult.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00000] in :0 [mono-rt] at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in :0
从堆栈跟踪中,我感觉这可能是 linker 的问题,但我已经尝试了所有 3 个设置(不要 link、link仅 SDK 程序集,link 全部)。当在这里和那里更改一些代码时,有时堆栈跟踪会略有不同,但没有什么真正有用的。这是我正在使用的编译设置:
应用程序有时会成功启动而无需随时更改。它只会工作一次。
我错过了什么?
确保您的 .NET 框架已打补丁。 Microsoft 发布了 .NET 补丁以允许可移植 Class 库正确找到合适的运行时 (KB2468871)。如果您看到上述异常(或类似异常),则表示您缺少最新的 .NET 框架补丁。
我很确定你在发行版中有一些奇怪的行为。由于您在 android 上使用单声道,因此您可以在 return 某处调用 await 函数 Task<T>
您不能使用 await 而是 .GetAwaiter().Result.