【问题标题】:UWP Windows 10 app crashes in release mode but works fine in debug modeUWP Windows 10 应用程序在发布模式下崩溃,但在调试模式下工作正常
【发布时间】:2016-04-23 20:38:10
【问题描述】:

我的 UWP 应用在发布模式下崩溃,在调试模式下工作正常,但我无法确定问题所在,但我知道这与从 System.Threading.Timer 和 MVVMLight 引发事件的组合有关.

我创建了一个新的虚拟应用程序并使用相同的代码(ZXing.net.mobile,我使用了 2 个可移植库,并使用了我自己的用户控件,这是他们的简化版本 - 我使用事件而不是 @987654321 @)。这很好用,我目前正在尝试添加更多步骤,即包括 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 码 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 用户控件的页面中,我有以下代码:

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 .

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

谢谢。

【问题讨论】:

  • 这可能是与 .NET Native 编译代码相关的问题吗?您是否尝试过启用“使用 .NET Native 工具链编译”进行调试?
  • 嗨,我已经尝试过了,我也尝试过选择“优化代码”,但在调试模式下仍然不会崩溃。

标签: win-universal-app mvvm-light zxing dispatcher


【解决方案1】:

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

这归结为一些事情!

  1. 我在 Releasemode 中使用了不同的 DataService,但未实现。通过实现,我的意思是我的所有函数都返回 NotImplementedException 或 null 值。

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

  3. 我触发了一系列 mvvmlight 事件 (Messenger.Default.Send),但没有一个事件检查错误或空值。

虽然所有这些都是由于我的验证不佳造成的,但这些错误在 Release 模式下的报告极差!如果从一开始,我就收到了 NullReferenceException 或任何类型的异常,它会立即将我引向正确的方向,但是抛出诸如我所遇到的错误是完全没用的,但它并没有但吸取了教训!!

我只能说,如果您遇到此问题,请不要浪费时间重写代码或尝试寻找解决方法。首先通过你的工作流程/事件链,希望你最终能抓住罪魁祸首。

希望这会有所帮助。

【讨论】:

  • 嗨,我的应用也有同样的问题。上次(如 6 个月前),我卸载了该应用程序,重新启动并再次安装,一切都很好。所以我不认为你或我的解决方案是一个真正的解决方案。现在我又遇到了错误,但是我不想像上次那样尝试重新安装,我想首先找出错误。当时,我读到这个 ​​ddl 的错误可能是由于系统方面的很多问题导致的,无法读取 dll 文件。或者 - 似乎是我的情况,注册表中的某种混乱引用,因为我需要访问图片目录。
  • 那么,你有没有再次遇到这个问题,并以另一种方式解决它?
【解决方案2】:

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

之所以想到这一点,是因为我正在研究此错误的另一个地方涉及某人通过升级其 NETCore 包来解决 SharedLibrary 问题,该案例是较早的案例 (5.x),但认为值得一试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-05
    • 2018-03-22
    • 2019-09-11
    • 1970-01-01
    • 1970-01-01
    • 2016-10-19
    • 2018-07-31
    • 2012-08-20
    相关资源
    最近更新 更多