ZXing.Net for Xamarin throws an Invalid Cast exception (occasionally)

Jan 17, 2014 at 1:39 PM
Hi,

using zxing.net in a ios application built with Xamarin.iOS.

Sometimes I get the following error that is crashing my application (both in iPad and iPhone):

The application is for iOS 7 devices.

In iPad:
Jan 17 10:06:24 Criticals-iPad MobileUIiOS[11754] <Warning>: Unhandled managed exception: Unable to cast object of type 'ZXing.Mobile.ZXingScannerViewController' to type 'MonoTouch.CoreMedia.CMSampleBuffer'. (System.InvalidCastException)
      at MonoTouch.ObjCRuntime.Runtime.GetINativeObject (IntPtr ptr, Boolean owns, System.Type target_type, System.Type implementation) [0x00000] in <filename unknown>:0 
      at MonoTouch.ObjCRuntime.Runtime.GetINativeObject_Dynamic (IntPtr ptr, Boolean owns, IntPtr type_ptr) [0x00000] in <filename unknown>:0 
      at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetINativeObject_Dynamic (intptr,int,intptr)
in iPhone:
Jan 17 13:29:38 Critical-iPhone MobileUIiOS[1980] <Warning>: Unhandled managed exception: Unable to cast object of type 'ZXing.Mobile.ZXingScannerViewController' to type 'MonoTouch.CoreMedia.CMSampleBuffer'. (System.InvalidCastException)
      at MonoTouch.ObjCRuntime.Runtime.GetINativeObject (IntPtr ptr, Boolean owns, System.Type target_type, System.Type implementation) [0x00000] in <filename unknown>:0 
      at MonoTouch.ObjCRuntime.Runtime.GetINativeObject_Dynamic (IntPtr ptr, Boolean owns, IntPtr type_ptr) [0x00000] in <filename unknown>:0 
      at (wrapper native-to-managed) MonoTouch.ObjCRuntime.Runtime:GetINativeObject_Dynamic (intptr,int,intptr)
Here is my code:
var scanner = new ZXing.Mobile.MobileBarcodeScanner();

MobileBarcodeScanningOptions options = new MobileBarcodeScanningOptions(); 
options.PossibleFormats.Add(ZXing.BarcodeFormat.CODE_128); 
options.PossibleFormats.Add(ZXing.BarcodeFormat.QR_CODE);

var result = await scanner.Scan(options, false);

if (result != null)
{
    string scanResult = result.Text;
..
Am I doing something wrong? Is there any workaround this?

Thanks,

L. Pinho
Coordinator
Jan 17, 2014 at 4:36 PM
Please open an issue at the ZXing.Net.Mobile project homepage at
https://github.com/Redth/ZXing.Net.Mobile
That's the Xamarin component which you are using.
It seems to me that the error isn't caused by the underlying ZXing.Net libraries.
So I can't help here.
Jan 17, 2014 at 6:31 PM
Ok then,

sorry for the confusion.

Thanks for advice
Coordinator
Jan 19, 2014 at 7:50 PM
no need for a sorry