UWP Windows 10应用程序在发布模式下崩溃,但在调试模式下工作正常

问题描述 投票:7回答:2

我的UWP应用程序在发布模式下崩溃并且在调试模式下工作正常,但是我不能指出问题是什么,但我知道它与从System.Threading.Timer和MVVMLight引发事件的组合有关。

我创建了一个新的虚拟应用程序并使用相同的代码(ZXing.net.mobile我使用了2个可移植库,我使用了自己的用户控件,这是他们的简化版本 - 我使用的是事件而不是<Action> )。 这工作正常,我正在尝试更多的步骤,包括mvvmlight和导航,但到目前为止,我无法重现这个虚拟应用程序中的问题。

我得到的错误是:

Unhandled exception at 0x58C1AF0B (mrt100_app.dll) in Company.MyApp.App.exe:
0xC0000602:  A fail fast exception occurred. Exception handlers will not be
 invoked and the process will be terminated immediately.

其次是:

Unhandled exception at 0x0107D201 (SharedLibrary.dll) in
Company.MyApp.App.exe: 0x00001007.

查看“线程”窗口时,如果有帮助,则其中一个工作线程具有以下信息。

Not Flagged >   4012    0   Worker Thread   <No Name>
    System.Private.Interop.dll!System.Runtime.InteropServices.
    ExceptionHelpers.ReportUnhandledError   Normal
    [External Code]  
     System.Private.Interop.dll!System.Runtime.InteropServices.ExceptionHelpers.
     ReportUnhandledError(System.Exception e) Line 885   
     System.Private.Interop.dll!Internal.Interop.InteropCallbacks.ReportUnhandledError
     (System.Exception ex) Line 17   
     System.Private.WinRTInterop.CoreLib.dll!Internal.WinRT.Interop.WinRTCallbacks.
     ReportUnhandledError(System.Exception ex) Line 274  
     System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.ReportUnhandledException
     (System.Exception exception) Line 152
     System.Private.Threading.dll!System.Threading.Tasks.AwaitTaskContinuation.
     ThrowAsyncIfNecessary(System.Exception exc) Line 784    
     System.Private.Threading.dll!System.Threading.WinRTSynchronizationContext.Invoker.
     InvokeCore() Line 182   
     System.Private.Threading.dll!System.Threading.WinRTSynchronizationContext.Invoker.
     Invoke(object thisObj) Line 162     
     System.Private.CoreLib.dll!System.Action<System.__Canon>.
     InvokeOpenStaticThunk(System.__Canon obj)
     System.Private.WinRTInterop.CoreLib.dll!Internal.WinRT.Interop.WinRTCallbacks.PostToCoreDispatcher.AnonymousMethod__0() Line 266    
     MyCompany.MyApp.App.exe
     MyCompany.MyApp.App.ViewModels.ValidateHandler.Invoke(string pin)
     MyCompany.MyApp.App.McgInterop.dll!McgInterop.ReverseComSharedStubs
     .Proc_(object __this, System.IntPtr __methodPtr) Line 6163
     MyCompany.MyApp.App.McgInterop.dll!Windows.UI.Core.DispatchedHandler__Impl.Vtbl.Invoke__STUB(System.IntPtr pComThis) Line 45147     
    [External Code]  

在我的QR Code UserControl中,它使用System.Threading.Timer并在找到QR码时引发事件:

timerPreview = new Timer(async (state) =>
{
   ....
   // Check if a result was found
   if (result != null && !string.IsNullOrEmpty(result.Text))
   {
     Debug.WriteLine("Barcode Found: " + result.Text);
     if (!this.ContinuousScanning)
     {
       delay = Timeout.Infinite;
       await StopScanningAsync();
     }
     else
     {
       delay = this.ScanningOptions.DelayBetweenContinuousScans;
     }
     OnBarcodeFound(result.Text);
   }

   timerPreview.Change(delay, Timeout.Infinite);

}, null, 
   this.ScanningOptions.InitialDelayBeforeAnalyzingFrames, 
   Timeout.Infinite);

在托管QRCode UserControl的页面中,我有以下代码:

private async void ScannerControl_BarcodeFound(string barcodeValue)
{
    var dispatcher = CoreApplication.MainView.CoreWindow.Dispatcher;

    await dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => {
        Debug.WriteLine(barcodeValue);
        GetViewModel.BarcodeFound(barcodeValue);
    });
}

如您所见,我将QrCode值传递给我的ViewModel,然后从那里发送消息然后重定向到另一个页面:

public void BarcodeFound(string barcodeData)
{
   Messenger.Default.Send<string>(barcodeData, MessengerTokens.QrCodeFound);
   this.NavigationFacade.NavigateToMyOtherPage();
}

我可以继续提供额外的代码,但是当我添加额外的断点时,我可以看到代码并传递正确的值并转到正确的位置,但最终会抛出此错误。 如果我添加其他错误处理程序或调度程序代码,它最终会工作并按预期转到下一页但是当我单击CommandBar中的按钮时,它需要一段时间,它最终会抛出相同的错误,因此通过添加这些额外的一些代码,我觉得我只是在进一步推进这个问题。

任何人都对我如何解决这个问题有任何建议。 我希望我可以分享完整的应用程序,但绝对不能。 所以我知道提供解决方案很难,但如果有人有建议我会很感激他们。

正如我所说,我认为这个问题是线程和mvvmlight相结合的结果,但令我疯狂的是,到目前为止,我的测试应用程序完全正常工作,所以我很确定它不是Zxing或我的UserControl。

任何帮助,建议将不胜感激,或者如果您需要我提供其他信息,请告诉我什么,我会尽力提供。

谢谢。

win-universal-app mvvm-light zxing dispatcher
2个回答
0
投票

嗯,这是一项艰苦的练习,浪费了我的时间!

这是一些事情!

  1. 我在Release模式下使用了另一个未实现的DataService。 通过实现,我的意思是我的所有函数都返回NotImplementedExceptionnull值。

  2. 将模型传递给我的ViewModel时,我没有检查它是否为null,从而导致未处理的exceptions

  3. 我有一连串的mvvmlight事件(Messenger.Default.Send <>)被触发,没有人检查错误或空值。

虽然所有这些都是由我的验证不良引起的,但这些错误在Release模式下报告极差! 如果从开始,我收到了NullReferenceException或任何类型的例外,它会立即让我朝着正确的方向,但抛出我所拥有的错误是完全没用但但它没有教训!

我只能说,如果这个问题发生在你身上,不要浪费你的时间重写代码或试图找到解决方法。 首先按照您的工作流程/事件链进行工作,希望您最终能够抓住罪魁祸首。

希望这可以帮助。


0
投票

遗憾的是,我们遇到了类似的问题,我们的问题涉及在应用程序中设置更改本地化的限定符值,但是出现了神秘失败的快速/ SharedLibrary本机错误。 将Microsoft.NETCore.UniversalWindowPlatform包从6.0.4升级到6.0.7似乎解决了这个问题。

只考虑到这一点,因为我正在研究这个错误的另一个地方涉及有人通过升级他们的NETCore包来解决SharedLibrary问题,那个案例是早期的(5.x),但认为它值得一试。

© www.soinside.com 2019 - 2024. All rights reserved.