Redth / ZXing.Net.Mobile

Barcode Scanner for Xamarin.iOS, Xamarin.Android, UWP and Tizen
MIT License
1.07k stars 701 forks source link

Crashes with universal app when in Release mode #304

Closed tfierens closed 8 years ago

tfierens commented 8 years ago

Hi,

Only spotted this today, after using your library for the last 3 weeks... In debug mode. Once my configuration is to Release, it initializes the camera as expected, I can cancel the action without any problems but the second it find a QR code, it bombs out and I get the following error:

Unhandled exception at 0x76E06D7E (combase.dll) in MyCompany.MyApp.App.exe: 0xC000027B: An application-internal exception has occurred (parameters: 0x0B369550, 0x00000002).

I thought it was because I was using the UserControl instead of the ScanPage and maybe I had left some code out but this is not the case as the same problem occurs with your universal app sample.

I've spent hours trying to figure out what's wrong and unfortunately can't. It reads the barcode correctly and the problem seems to be when it gets out of the timer loop and the event is raised back. When it bombs out, it displays the following code:

        public static global::System.IntPtr pNativeVtable;
        [global::System.Runtime.InteropServices.McgGeneratedMarshallingCode]
        [global::System.Runtime.InteropServices.NativeCallable]
        static int Invoke__STUB(global::System.IntPtr pComThis)
        {
            object __this = global::System.Runtime.InteropServices.McgMarshal.ThisPointerToTargetObject(pComThis);
            global::System.IntPtr __methodPtr = global::McgInterop.Intrinsics.VirtualAddrOf<global::Windows.UI.Core.DispatchedHandler>(
                                __this, 
                                0
                            );
            int __ret = ((int)global::McgInterop.ReverseComSharedStubs.Proc_(
                                __this, 
                                __methodPtr
                            ));
            global::System.Runtime.InteropServices.DebugAnnotations.PreviousCallContainsUserCode();
            return __ret;
        }

I don't understand why this works perfectly in debug mode but the problem occurs only in Release mode. It should be easily reproducible if you don't have a Windows Phone as it happens on both my laptops.

I really hope you can help as this is rather urgent. Sorry.

Thanks

Thierry.

tfierens commented 8 years ago

Not a bug with Zxing.Net.Mobile! Problem with my code! Took forever to figure out due to poor error description from .NET when in release mode, but definitely not a bug with Zxing which is a relief!

Redth commented 8 years ago

Sounds like this could have been a linker issue... ?

tfierens commented 8 years ago

I'll google that later. I thought it was a combination of being in Release mode, having missed validation and having a chain of mvvmlight events being raised, but you think it should still have raised a proper .net Exception and/or Stacktrace even when in release mode? Thanks.

chevonc commented 8 years ago

@tfierens Did you ever figure out what is going on here? I think I am running into a similar issue and would love to know if you found a solution

tfierens commented 8 years ago

@chevonc I did abd it had nothing to do with Zxing. It was combination of things. I was using my release data service which i hadn't implemented, so it was returning a null value for core object which was being passed to an mvvmlight messenger event, then to another an so forth, but zxing did work properly when reading the qr code. The major problem was that .net was not returning a proper exception and/or stacktrace. Don't know if it's.net or mvvmlight that's at the source of the poor error reporting problem but it's definitely worth stepping through your code in release mode and see what values you can inspect. Won't be obvious at time since in release mode, but try that. Spent a huge amount of time looking at the wrong place but for obvious reasons but it was not down to zxing. May be share your error/problem/code. It might help resolve the problem.