我的UWP应用程序在发布模式下崩溃并且在调试模式下工作正常但我无法确定问题是什么,但我知道它与从系统中提升事件的组合相关.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。
任何帮助,建议都将不胜感激,或者如果您需要我提供其他信息,请告诉我我将尝试提供的内容。
感谢。
答案 0 :(得分:0)
嗯,这是一项艰苦的练习,浪费了我的时间!
这取决于一些事情!!
我在Release
模式下使用的是另一个未实现的DataService。实施后,我的意思是我的所有功能都返回NotImplementedException
或null
值。
将模型传递给我的ViewModel时,我没有检查它是否为null,因此导致未处理exceptions
。
我有一连串的mvvmlight事件(Messenger.Default.Send&lt;&gt;)被触发,没有人检查错误或空值。
虽然所有这些都是由于我的验证不当造成的,但这些错误在Release
模式下的报道极差!如果从开始,我收到了NullReferenceException或任何类型的例外,它会立即让我朝着正确的方向,但抛出我所拥有的错误是完全没用但但它没有教训!!
我只能说,如果这个问题发生在你身上,不要浪费你的时间重写代码或试图找到解决方法。首先按照您的工作流程/事件链进行工作,希望您最终能够抓住罪魁祸首。
希望这有帮助。
答案 1 :(得分:0)
可悲的是,我们遇到了类似的问题,我们的问题涉及在应用程序中设置更改本地化的限定符值,但是出现了神秘失败的快速/ SharedLibrary本机错误。将Microsoft.NETCore.UniversalWindowPlatform包从6.0.4升级到6.0.7似乎解决了这个问题。
只考虑到这一点,因为我正在研究这个错误的另一个地方涉及有人通过升级他们的NETCore包来解决SharedLibrary问题,那个案例是早期版本(5.x),但认为它值得一试。