【发布时间】:2020-02-23 10:21:28
【问题描述】:
我在 mac 上使用 Visual Studio 2017 和 Visual Studio 2017。 Mono 版本是 5.18.1,Xamarin.iOS 版本是 12.4(我认为)。该应用程序运行良好,没有任何问题。最近我已将 Windows 和 Mac 上的 Visual Studios 更新到 2019,Xamarin.iOS 版本已更新到 13.4。现在,该应用程序在模拟器和装有 iOS 13.1 的 iPhone 上都出现了“奇怪”的崩溃。但在 iOS 12.4 的模拟器上,该应用程序运行顺畅。此外,在应用商店中发布的应用(使用 Xamarin.iOS 12.4 构建)在 iOS 13.1 设备中可以正常工作。
该应用在执行一些与动画相关的工作时似乎崩溃了,这是来自 AppCenter 的崩溃日志。
Application Specific Information:
*** Terminating app due to uncaught exception 'SIGABRT', reason: 'Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Native stack trace:
**some native trace**
Xamarin Exception Stack:
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Modifications to the layout engine must not be performed from a background thread after it has been accessed from the main thread.
Native stack trace:
**some native trace**
at ObjCRuntime.Runtime.ThrowNSException (System.IntPtr ns_exception) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2/src/Xamarin.iOS/ObjCRuntime/Runtime.cs:406
at ObjCRuntime.Runtime.throw_ns_exception (System.IntPtr exc) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/runtime/Delegates.generated.cs:128
at (wrapper native-to-managed) ObjCRuntime.Runtime.throw_ns_exception(intptr)
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper(intptr,intptr)
at UIKit.UIView.LayoutSubviews () [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2/src/Xamarin.iOS/UIView.g.cs:1290
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].LayoutSubviews () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:289
at null.null
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSendSuper(intptr,intptr)
at UIKit.UIView.LayoutSubviews () [0x00023] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2/src/Xamarin.iOS/UIView.g.cs:1290
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].LayoutSubviews () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:289
at null.null
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
at CoreAnimation.CATransaction.Commit () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/13.4.0.2/src/Xamarin.iOS/CATransaction.g.cs:90
at Xamarin.Forms.Platform.iOS.CADisplayLinkTicker.StartThread () [0x0003a] in D:\a\1\s\Xamarin.Forms.Platform.iOS\CADisplayLinkTicker.cs:61
at System.Threading.ThreadHelper.ThreadStart_Context (System.Object state) [0x00014] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/threading/thread.cs:74
at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910
at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state) [0x0002b] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:899
at System.Threading.ThreadHelper.ThreadStart () [0x00008] in /Users/builder/jenkins/workspace/xamarin-macios/xamarin-macios/external/mono/mcs/class/referencesource/mscorlib/system/threading/thread.cs:111
有谁知道这可能是什么问题? :(
【问题讨论】:
-
这可能意味着您正在后台线程或类似的东西中更新一些 UI。您能否调试代码以查看崩溃发生的位置并检查您是否正在那里更新 UI。您可以使用
dispatch_async(dispatch_get_main_queue(), ^{ });在主线程中运行代码。 -
@JackHua-MSFT 调试没有帮助。调试期间发生的崩溃,在我打开应用程序而不附加调试器时没有重现。这很奇怪。
-
调试过程中发生的崩溃,你能知道它是在哪个页面崩溃的吗?检查那里的代码。
-
以上注释中的代码示例是针对 Obj-C 的。在 Xamarin.Forms 中,使用以下内容保证代码在 UI/主线程上运行:
Device.BeginInvokeOnMainThread(Action)docs.microsoft.com/en-us/dotnet/api/… -
我已经用帮助类检查了所有代码,以检查当前线程是否是主线程。但是所有与崩溃相关的地方都在主线程上。所以不是我。
标签: xamarin xamarin.forms xamarin.ios core-animation ios13