Redth / ZXing.Net.Maui

Barcode Scanning for MAUI?
MIT License
478 stars 153 forks source link

Value cannot be null. (Parameter 'device') #133

Open diogopineda opened 1 year ago

diogopineda commented 1 year ago

I am implementing the barcode reader and I am facing this Issue in my app. It only happens on iOS. I downloaded the Sample and the same problem happens, changing nothing, when trying to open the camera.

Steps to reproduce: 1 - Download the Sample Project. 2 - Set BigIslandBarcode as Startup project 3 - Run the app and click on main page:

_{System.ArgumentNullException: Value cannot be null. (Parameter 'device') at ObjCRuntime.ThrowHelper.ThrowArgumentNullException(String argumentName) at ObjCRuntime.NativeObjectExtensions.GetNonNullHandle(INativeObject self, String argumentName) at AVFoundation.AVCaptureDeviceInput..ctor(AVCaptureDevice device, NSError& error) at ZXing.Net.Maui.CameraManager.UpdateCamera() in D:\projects\ZXing.Net.Maui-main (2)\ZXing.Net.Maui-main\ZXing.Net.MAUI\Apple\CameraManager.ios.maccatalyst.cs:line 129 at ZXing.Net.Maui.CameraManager.UpdateCameraLocation(CameraLocation cameraLocation) in D:\projects\ZXing.Net.Maui-main (2)\ZXing.Net.Maui-main\ZXing.Net.MAUI\CameraManager.cs:line 25 at ZXing.Net.Maui.CameraBarcodeReaderViewHandler.<>c.<.cctor>b18_1(CameraBarcodeReaderViewHandler handler, ICameraBarcodeReaderView virtualView) in D:\projects\ZXing.Net.Maui-main (2)\ZXing.Net.Maui-main\ZXing.Net.MAUI\CameraBarcodeReaderViewHandler.cs:line 17 at Microsoft.Maui.PropertyMapper`2.<>c__DisplayClass5_0[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[ZXing.Net.Maui.CameraBarcodeReaderViewHandler, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler2[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIView, Microsoft.iOS, Version=16.2.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2[[ZXing.Net.Maui.ICameraBarcodeReaderView, ZXing.Net.MAUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[UIKit.UIView, Microsoft.iOS, Version=16.2.0.0, Culture=neutral, PublicKeyToken=84e04ff9cfb79065]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.LayoutHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.ILayout, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.LayoutView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.ContentViewHandler.UpdateContent(IContentViewHandler handler) at Microsoft.Maui.Handlers.ContentViewHandler.MapContent(IContentViewHandler handler, IContentView page) at Microsoft.Maui.PropertyMapper2.<>cDisplayClass5_0[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IContentViewHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ContentViewHandler.SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2[[Microsoft.Maui.IContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Platform.ContentView, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.set_Handler(IElementHandler value) at Microsoft.Maui.Controls.VisualElement.Microsoft.Maui.IElement.set_Handler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.ToHandler(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToPlatform(IElement view, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.ToUIViewController(IElement view, IMauiContext context) at Microsoft.Maui.Handlers.WindowHandler.MapContent(IWindowHandler handler, IWindow window) at Microsoft.Maui.PropertyMapper`2.<>cDisplayClass5_0[[Microsoft.Maui.IWindow, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[Microsoft.Maui.Handlers.IWindowHandler, Microsoft.Maui, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]].b0(IElementHandler h, IElement v) at Microsoft.Maui.PropertyMapper.UpdatePropertyCore(String key, IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.PropertyMapper.UpdateProperties(IElementHandler viewHandler, IElement virtualView) at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view) at Microsoft.Maui.Controls.Element.SetHandler(IElementHandler newHandler) at Microsoft.Maui.Controls.Element.setHandler(IElementHandler value) at Microsoft.Maui.Platform.ElementExtensions.SetHandler(INativeObject nativeElement, IElement element, IMauiContext context) at Microsoft.Maui.Platform.ElementExtensions.SetWindowHandler(UIWindow platformWindow, IWindow window, IMauiContext context) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IApplication application, UIWindowScene windowScene, NSDictionary[] states) at Microsoft.Maui.Platform.ApplicationExtensions.CreatePlatformWindow(IUIApplicationDelegate platformApplication, IApplication application, UIApplication uiApplication, NSDictionary launchOptions) at Microsoft.Maui.MauiUIApplicationDelegate.FinishedLaunching(UIApplication application, NSDictionary launchOptions) at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) at BigIslandBarcode.Program.Main(String[] args) in D:\projects\ZXing.Net.Maui-main (2)\ZXing.Net.Maui-main\BigIslandBarcode\Platforms\iOS\Program.cs:line 12}

sahadevgupta commented 1 year ago

@diogopineda Are you trying to deploy the app on iOS simulator ? If yes then you will get the above error as the iOS simulator does not support camera.

diogopineda commented 1 year ago

Ok, on real device I dont have the crash, but nothing happens, it does not open the camera.

zoanthal commented 1 year ago

I have the same problem. It does crash on the real device.