Windows 10 UWP application crashes in release mode, but works fine in debug mode

My UWP application crashes in release mode and works fine in debug mode, but I canโ€™t say what the problem is, but I know that this is due to the combination of raising an event from System.Threading.Timer and MVVMLight.

I created a new dummy application and used the same code (ZXing.net.mobile, where I used 2 portable libraries, and I used my own custom control, which is a simplified version of them). I use events instead of <Action> ). This works great, and I'm currently trying to add extra steps to it, i.e. enable mvvmlight and navigation, but so far I canโ€™t reproduce the problem in this dummy application.

The error I am getting is:

 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. 

The following are:

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

When viewing the Threads window, one of the workflows has the following information, if that helps.

 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] 

In my UserControl QR code, it uses System.Threading.Timer, and it fires an event when a QR code is detected:

 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); 

On the page that the UserControl QRCode is hosted on, I have the following code:

 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); }); } 

As you can see, I pass the QrCode value to my ViewModel, and from there I sent a message and then redirected it to another page:

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

I could go ahead and provide additional code, but as additional breakpoints are added, I see that the code and passing the correct value and going to the right place, but in the end it throws this error. If I add additional error handlers or a dispatcher code, it eventually works and goes to the next page as expected, but when I click on the button in my CommandBar, it takes some time, and in the end it causes the same error, so adding these extra bits of code, I feel like I'm just giving up the problem further down the line.

Does anyone have any suggestions on how I will get around this issue. I'm sorry that I can not share the full application, but definitely can not. Therefore, I know that it will be difficult to provide a solution, but if anyone has suggestions, I will be grateful to them.

As I said, I think the problem is with the combination of streams and mvvmlight, but it makes me wonder if my test application is working as expected, so I'm sure this is not Zxing or my UserControl.

Any help, suggestions would be appreciated or if you need to provide additional information, please tell me that I will try to provide.

Thanks.

+5
source share
2 answers

Well, it was a painstaking exercise and a huge waste of my time!

This was due to several things!

  • I used another DataService method in Release that was not implemented. By implementation, I mean that all my functions returned NotImplementedException or null values.

  • When passing my model to my ViewModel, I did not check to see if it was null, which resulted in unhandled exceptions .

  • I had a mvvmlight event chain (Messenger.Default.Send <>) and no one checked for errors or null values.

Although they were all caused by poor validation on my part, these errors are extremely poorly described in Release mode! if from the very beginning I got a NullReferenceException or any exceptions, it would immediately lead me in the right direction, but throwing errors like what I had was completely useless, but it wasnโ€™t !!

All I can say is that if this problem ever happens to you, do not waste time rewriting the code or trying to find workarounds. Work through your workflow / chain of events first and hopefully you eventually catch the culprit.

Hope this helps.

0
source

Unfortunately, we encountered a similar problem, ours was related to setting the classifier values โ€‹โ€‹to change localization on the fly in the application, but it came with a secret error with an error / with SharedLibrary own errors. Updating the Microsoft.NETCore.UniversalWindowPlatform package from 6.0.4 to 6.0.7 seems to fix the problem.

I just thought about it, because in another place where I investigated this error, someone solved the SharedLibrary problem by updating their NETCore package, this case was earlier (5.x), but thought it was worth it.

0
source

Source: https://habr.com/ru/post/1247787/


All Articles