Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashing on try to scan on IOS #100

Open
DerLud3 opened this issue Jan 6, 2022 · 23 comments
Open

App crashing on try to scan on IOS #100

DerLud3 opened this issue Jan 6, 2022 · 23 comments
Labels
help wanted Extra attention is needed

Comments

@DerLud3
Copy link

DerLud3 commented Jan 6, 2022

Hello guys,

I just wanted to implement the Scanner in my App, but everytime i try to scan the app crash. So i tried it with the sample app and here its not working too.

This is the Exception output.

An error occurred: 'Could not create an native instance of the type 'Firebase.MLKit.Vision.VisionImageMetadata': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: '  at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:312 
  at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:180 
  at Firebase.MLKit.Vision.VisionImageMetadata..ctor () <0x12288e5c8 + 0x00008> in <8607cf18847b4467a58b3fd7d84f75f1>:0 
  at GoogleVisionBarCodeScanner.UICameraPreview+CaptureVideoDelegate..ctor (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer) [0x0002f] in C:\Users\Kliem\source\repos\Sample\BarcodeScanner.XF\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:288 
  at GoogleVisionBarCodeScanner.UICameraPreview.Initialize (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer) [0x000cb] in C:\Users\Kliem\source\repos\Sample\BarcodeScanner.XF\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:182 
  at GoogleVisionBarCodeScanner.UICameraPreview..ctor (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer, GoogleVisionBarCodeScanner.CameraFacing cameraFacing, GoogleVisionBarCodeScanner.CaptureQuality captureQuality) [0x00016] in C:\Users\Kliem\source\repos\Sample\BarcodeScanner.XF\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:35 
  at GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs`1[TElement] e) [0x0006b] in C:\Users\Kliem\source\repos\Sample\BarcodeScanner.XF\GoogleVisionBarCodeScanner\iOS\Renderer\CameraViewRenderer.cs:32 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x00172] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:296 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283 
  at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 
  at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 
  at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:251 
  at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr)
  at UIKit.UIViewController.get_View () [0x0002a] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIViewController.g.cs:2844 
  at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:103 
  at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:119 
  at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:374 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:352 
  at Xamarin.Forms.Platform.iOS.NavigationRenderer.<ViewDidLoad>b__47_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:239 
  at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 
  at (wrapper delegate-invoke) <Module>.invoke_void_object(object)
  at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178 
--- End of stack trace from previous location where exception was thrown ---

  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x00047] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:79 
  at SampleApp.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\Kliem\source\repos\Sample\BarcodeScanner.XF\SampleApp\SampleApp.iOS\Main.cs:17 
  at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '

I figured out that when i am builduing the app, this output is shown:

Skipping invalid framework FirebaseCore.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\FirebaseCore.framework\FirebaseCore (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseCoreDiagnostics.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\FirebaseCoreDiagnostics.framework\FirebaseCoreDiagnostics (Aufgaben-ID: 80)
2>  Skipping invalid framework GoogleDataTransport.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\GoogleDataTransport.framework\GoogleDataTransport (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseInstallations.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\FirebaseInstallations.framework\FirebaseInstallations (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseInstanceID.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\FirebaseInstanceID.framework\FirebaseInstanceID (Aufgaben-ID: 80)
2>  Skipping invalid framework TFLTensorFlowLite.framework. Reason: Invalid executable obj\iPhone\Debug\device-builds\iphone9.3-15.1/Frameworks\TFLTensorFlowLite.framework\TFLTensorFlowLite (Aufgaben-ID: 80)
2>  Skipping invalid framework GoogleAppMeasurement.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\GAppM-6.9.0\Frameworks\GoogleAppMeasurement.framework\GoogleAppMeasurement (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLCommon.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLCmmn-0.21.0\Frameworks\FirebaseMLCommon.framework\FirebaseMLCommon (Aufgaben-ID: 80)
2>  Skipping invalid framework TensorFlowLiteC.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\TnsrFlwLtC-2.3.0\TensorFlowLiteC-2.3.0\Frameworks\TensorFlowLiteC.framework\TensorFlowLiteC (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVision.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsn-0.21.0\Frameworks\FirebaseMLVision.framework\FirebaseMLVision (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionAutoML.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnA-0.21.0\Frameworks\FirebaseMLVisionAutoML.framework\FirebaseMLVisionAutoML (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionBarcodeModel.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnB-0.21.0\Frameworks\FirebaseMLVisionBarcodeModel.framework\FirebaseMLVisionBarcodeModel (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionFaceModel.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnF-0.21.0\Frameworks\FirebaseMLVisionFaceModel.framework\FirebaseMLVisionFaceModel (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionLabelModel.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnL-0.21.0\Frameworks\FirebaseMLVisionLabelModel.framework\FirebaseMLVisionLabelModel (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionTextModel.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnT-0.21.0\Frameworks\FirebaseMLVisionTextModel.framework\FirebaseMLVisionTextModel (Aufgaben-ID: 80)
2>  Skipping invalid framework FirebaseMLVisionObjectDetection.framework. Reason: Invalid executable C:\Users\Kliem\AppData\Local\XamarinBuildDownloadCache\FMLVsnO-0.21.0\Frameworks\FirebaseMLVisionObjectDetection.framework\FirebaseMLVisionObjectDetection (Aufgaben-ID: 80)
2>  

Can someone help me?

@JoergTie
Copy link

Hi,
I have the same problem. Is there any solution?

@DerLud3
Copy link
Author

DerLud3 commented Feb 1, 2022

So i switched to ZXing Scanner by Redth.

@JoergTie
Copy link

JoergTie commented Feb 1, 2022

@JimmyPun610 : I tried older versions of BarcodeScanner.XF. None of them worked. Even the sampleproject crashes on iOS with the same Exception: 'Could not create an native instance of the type 'Firebase.MLKit.Vision.VisionBarcodeDetectorOptions': the native class hasn't been loaded.
What's wrong?

Thanks in advance

@JimmyPun610
Copy link
Owner

Hi @JoergTie ,

Just built for my iPhone 11, iOS 15 and it looks working.
What version of iOS device are you using and is that a simulator?

For this issue, it is probably caused by building for an unsupported architectures.
Or another possible reason is the MLKit library changed in the latest version.
I found that the core library has updated but the .NET binding is not published yet. Will check it out later

@JoergTie
Copy link

JoergTie commented Feb 2, 2022

@JimmyPun610 :I use a iPhone SE iOS15.2.1, Visual Studio 2022 on Windows. Connected to a Macbook (15.2) with Xamarin.iOS xamarin.ios-15.4.0.0.pkg

@JimmyPun610
Copy link
Owner

@JimmyPun610 :I use a iPhone SE iOS15.2.1, Visual Studio 2022 on Windows. Connected to a Macbook (15.2) with Xamarin.iOS xamarin.ios-15.4.0.0.pkg

The latest version of official releases are not published yet. I built from their source code and created an update.
I have updated to 6.2.0.0-pre and you may have a try to see if the error still exist, but you would need to do more settings in visual studio.

  1. Download the nuget packages from https://github.com/JimmyPun610/BarcodeScanner.XF/tree/master/GoogleVisionBarCodeScanner/iOS/Nuget
  2. Set the nuget 3rd location for the location of these packages

Please make sure you have set the architecture to ARM64 only.

@JoergTie
Copy link

@JimmyPun610 : Thank you so much for your help, I still get an exception but a different one:
Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded.

here are my project settings after using your nuget packages:

netstandard2.0 true x64 ...

@JoergTie
Copy link

&ltProject Sdk="Microsoft.NET.Sdk">

&ltPropertyGroup>
&ltTargetFramework>netstandard2.0&lt/TargetFramework>
&ltProduceReferenceAssembly>true&lt/ProduceReferenceAssembly>
&ltPlatformTarget>x64&lt/PlatformTarget>
&lt/PropertyGroup>

&ltItemGroup>
&ltPackageReference Include="BarcodeScanner.XF" Version="6.2.0-pre" />
&ltPackageReference Include="Microsoft.Azure.Mobile.Client" Version="4.2.0" />
&ltPackageReference Include="Microsoft.Azure.Mobile.Client.SQLiteStore" Version="4.2.0" />
&ltPackageReference Include="Xam.Plugin.Connectivity" Version="3.2.0" />
&ltPackageReference Include="Xam.Plugin.Media" Version="5.0.1" />
&ltPackageReference Include="Xamarin.Firebase.iOS.Core" Version="8.10.0" />
&ltPackageReference Include="Xamarin.Forms" Version="5.0.0.2337" />
&ltPackageReference Include="Xamarin.Essentials" Version="1.7.1" />
&ltPackageReference Include="Xamarin.MLKit.iOS.BarcodeScanning" Version="1.6.0" />
&ltPackageReference Include="Xamarin.MLKit.iOS.Core" Version="5.0.0" />
&lt/ItemGroup>

comment: &lt replaces <

@JimmyPun610
Copy link
Owner

@JimmyPun610 : Thank you so much for your help, I still get an exception but a different one: Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded.

here are my project settings after using your nuget packages:

netstandard2.0 true x64 ...

Hi @JoergTie ,

I cannot reproduce this error. What about if you just include the BarcodeScanner.XF in your projects but not that 3 Firebase/MLKit packages?

Another suggestion is that download the BarcodeScanner.XF source project, import to your solution and add it to your Xamarin project as reference.

If all of above suggestion is not working, it would be nice if you could share a sample project for me

@JoergTie
Copy link

Hi @JimmyPun610,
very simple to reproduce:
I just take your latest sample solution (https://github.com/JimmyPun610/BarcodeScanner.XF/tree/master/SampleApp)
With Android it works fine. With iOS it crashes and I get this debuggger output:

2022-02-14 01:45:41.944 Xamarin.PreBuilt.iOS[4720:2354019] Xamarin.iOS: Successfully received USB connection from the IDE on port 10000, fd: 7
2022-02-14 01:45:41.951 Xamarin.PreBuilt.iOS[4720:2354019] Xamarin.iOS: Processing: 'start profiler: no'
2022-02-14 01:45:41.952 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Profiler not loaded (disabled)

Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/Xamarin.iOS.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/Mono.Security.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/Xamarin.PreBuilt.iOS.exe [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/Xamarin.iOS.HotRestart.Application.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/netstandard.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Xml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Numerics.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Data.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Transactions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Data.DataSetExtensions.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Drawing.Common.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.IO.Compression.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.IO.Compression.FileSystem.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.ComponentModel.Composition.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Net.Http.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Runtime.Serialization.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.ServiceModel.Internals.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Web.Services.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/System.Xml.Linq.dll [External]
Thread started: #2
Thread started: #3
2022-02-14 01:45:42.608 Xamarin.PreBuilt.iOS[4720:2353999] Content folder: /var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content

2022-02-14 01:45:42.609 Xamarin.PreBuilt.iOS[4720:2353999] App path /var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/SampleApp.iOS.exe

2022-02-14 01:45:42.609 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Platform.iOS' (culture: '')

2022-02-14 01:45:42.609 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Platform.iOS' (culture: '')

Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/SampleApp.iOS.exe
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Xamarin.Forms.Platform.iOS.dll [External]
2022-02-14 01:45:42.620 Xamarin.PreBuilt.iOS[4720:2353999] AppDelegate name: AppDelegate

Thread started: #4
Thread started: #5
Thread started: #6
Thread started: #7
2022-02-14 01:45:42.865 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Core' (culture: '')

2022-02-14 01:45:42.866 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Core' (culture: '')

Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Xamarin.Forms.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Xamarin.Forms.Platform.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/MLKit.BarcodeScanning.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/MLKit.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Plugin.Media.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/SampleApp.dll
2022-02-14 01:45:42.924 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Xaml' (culture: '')

2022-02-14 01:45:42.925 Xamarin.PreBuilt.iOS[4720:2353999] Xamarin.iOS: Unable to locate assembly 'Xamarin.Forms.Xaml' (culture: '')

Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Xamarin.Forms.Xaml.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/BarcodeScanner.XF.dll
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Firebase.Core.dll [External]
Loaded assembly: /private/var/containers/Bundle/Application/0E2788E8-C527-46CF-9477-E4032E569CC4/SampleApp.iOS.app/SampleApp.iOS.content/Xamarin.Essentials.dll [External]
Thread started: #8
[0:] An error occurred: 'Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:327
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSObject2.cs:184
at MLKit.BarcodeScanning.BarcodeScannerOptions..ctor (MLKit.BarcodeScanning.BarcodeFormat formats) <0x104bfc7d0 + 0x00008> in :0
at GoogleVisionBarCodeScanner.UICameraPreview+CaptureVideoDelegate..ctor (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer) [0x0007b] in D:\BarcodeScanner.XF-master\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:294
at GoogleVisionBarCodeScanner.UICameraPreview.Initialize (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer) [0x000cb] in D:\BarcodeScanner.XF-master\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:183
at GoogleVisionBarCodeScanner.UICameraPreview..ctor (GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer renderer, GoogleVisionBarCodeScanner.CameraFacing cameraFacing, GoogleVisionBarCodeScanner.CaptureQuality captureQuality) [0x00016] in D:\BarcodeScanner.XF-master\GoogleVisionBarCodeScanner\iOS\UICameraPreview.cs:36
at GoogleVisionBarCodeScanner.Renderer.CameraViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) [0x0006b] in D:\BarcodeScanner.XF-master\GoogleVisionBarCodeScanner\iOS\Renderer\CameraViewRenderer.cs:32 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00172] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:296
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51
at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:251
at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr)
at UIKit.UIViewController.get_View () [0x0002a] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/ios/native/UIKit/UIViewController.g.cs:2847
at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:103
at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:119
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240
at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:374
at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:352
at Xamarin.Forms.Platform.iOS.NavigationRenderer.b__47_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:239
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at (wrapper delegate-invoke) .invoke_void_object(object)
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:83
at SampleApp.iOS.Application.Main (System.String[] args) [0x00001] in D:\BarcodeScanner.XF-master\SampleApp\SampleApp.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
Die App wurde beendet.

@Pranse2003
Copy link

Hi @JimmyPun610,
I'am also having the exact same problem as JoergTie when trying your latest sampleapp on my Iphone XR ios 15.5.
The app is build in Visual studio 2022 Version 17.2.2 on a windows machine paired to a mac mini with Xcode 13.4
In appDelegate.cs:
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
// Keep app alive for debugging
UIApplication.SharedApplication.IdleTimerDisabled = true;

        global::Xamarin.Forms.Forms.Init();
        LoadApplication(new App());
        GoogleVisionBarCodeScanner.iOS.Initializer.Init();
        Firebase.Core.App.Configure(); //<- This fix does not work anymore as of (may) 2022?
        return base.FinishedLaunching(app, options);
    } 

I have put a lot of time searching for a solution to make this work in ios.
I realy hope you may have some good ideas about it?

@JimmyPun610
Copy link
Owner

Hi @Pranse2003 ,

Yeah, the Firebase.Core.App.Configure(); is no longer needed.
For your issue, I am not sure if it is caused by IDE...
Did you try belows?
A:

  1. Update MacOS, XCode, Visual Studio for Mac and Visual Studio 2022 (not sure if 2019 still work in iOS) in Windows to latest version
  2. Remove .bin and .obj for all projects.
  3. Pair the mac in Windows.
  4. Build the project again.

B:

  1. Update MacOS, XCode and Visual Studio for Mac.
  2. Remove .bin and .obj for all projects.
  3. Use Visual Studio for Mac to build the project.

@JimmyPun610 JimmyPun610 added the help wanted Extra attention is needed label Jun 9, 2022
@lowellburns
Copy link

I am having this crash with iOS as well. It happens whether I use Xamarin Forms or Maui.

Visual Studio 17.3.0
Debugging to a Local Device (phone running iOS 15.6)

Here is a video replicating it with the SampleApp.Maui. It first requires changing the sample app to target iOS.
https://www.loom.com/share/25eee64e615d421c8986a47571323dfa

The call stack shows it is happening in the iOS CaptureVideoDelegate.

@JimmyPun610
Copy link
Owner

I am having this crash with iOS as well. It happens whether I use Xamarin Forms or Maui.

Visual Studio 17.3.0 Debugging to a Local Device (phone running iOS 15.6)

Here is a video replicating it with the SampleApp.Maui. It first requires changing the sample app to target iOS. https://www.loom.com/share/25eee64e615d421c8986a47571323dfa

The call stack shows it is happening in the iOS CaptureVideoDelegate.

Hi @lowellburns ,

Did you tried to use Visual Studio for Mac to build to see if it success?

@gkenaston
Copy link

gkenaston commented Aug 13, 2022

@JimmyPun610 I'm having the same issue on iOS 15.6 using the MAUI project. Android works great :)

[0:] An error occurred: 'Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject(Boolean alloced) at Foundation.NSObject..ctor(NSObjectFlag x) at MLKit.BarcodeScanning.BarcodeScannerOptions..ctor(BarcodeFormat formats) at BarcodeScanner.Mobile.Maui.Platforms.iOS.CaptureVideoDelegate..ctor(ICameraView cameraView) at BarcodeScanner.Mobile.Maui.CameraViewHandler.Connect() at BarcodeScanner.Mobile.Maui.CameraViewHandler.ConnectHandler(UICameraPreview nativeView) at Microsoft.Maui.Handlers.ViewHandler2[[BarcodeScanner.Mobile.Maui.ICameraView, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, Culture=neutral, PublicKeyToken=null],[BarcodeScanner.Mobile.Maui.Platforms.iOS.UICameraPreview, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, Culture=neutral, PublicKeyToken=null]].OnConnectHandler(UIView platformView)
at Microsoft.Maui.Handlers.ViewHandler.OnConnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.ConnectHandler(Object platformView)
at Microsoft.Maui.Handlers.ElementHandler.SetVirtualView(IElement view)
at Microsoft.Maui.Handlers.ViewHandler2[[BarcodeScanner.Mobile.Maui.ICameraView, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, Culture=neutral, PublicKeyToken=null],[BarcodeScanner.Mobile.Maui.Platforms.iOS.UICameraPreview, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, Culture=neutral, PublicKeyToken=null]].SetVirtualView(IView view) at Microsoft.Maui.Handlers.ViewHandler2[[BarcodeScanner.Mobile.Maui.ICameraView, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, Culture=neutral, PublicKeyToken=null],[BarcodeScanner.Mobile.Maui.Platforms.iOS.UICameraPreview, BarcodeScanner.Mobile.Maui, Version=6.3.0.22, 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.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.<>c__DisplayClass5_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]].b__0(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.ViewExtensions.ToHandler(IView view, IMauiContext context)
at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.PushPage(Page page, Boolean animated, TaskCompletionSource1 completionSource) at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnPushRequested(NavigationRequestedEventArgs e) at Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnNavigationRequested(Object sender, NavigationRequestedEventArgs e) at Microsoft.Maui.Controls.ShellSection.InvokeNavigationRequest(NavigationRequestedEventArgs args) at Microsoft.Maui.Controls.ShellSection.OnPushAsync(Page page, Boolean animated) at Microsoft.Maui.Controls.ShellSection.PushStackOfPages(List1 pages, Nullable1 animate) at Microsoft.Maui.Controls.ShellSection.GoToAsync(ShellNavigationRequest request, ShellRouteParameters queryData, IServiceProvider services, Nullable1 animate, Boolean isRelativePopping)`

@lowellburns
Copy link

I am having this crash with iOS as well. It happens whether I use Xamarin Forms or Maui.
Visual Studio 17.3.0 Debugging to a Local Device (phone running iOS 15.6)
Here is a video replicating it with the SampleApp.Maui. It first requires changing the sample app to target iOS. https://www.loom.com/share/25eee64e615d421c8986a47571323dfa
The call stack shows it is happening in the iOS CaptureVideoDelegate.

Hi @lowellburns ,

Did you tried to use Visual Studio for Mac to build to see if it success?

We tried on Visual Studio for Mac. As it turns out when targeting an iOS simulator (instead of physical ios device) with Visual Studio for MAC or Vistual Studio on Windows the build fails because of the issue of native references. It is the same issue, but it is just caught at build time when targeting a simulator and runtime when deploying to a physical iOS device.

@nerriksolutions
Copy link

Was there a resolution to this found? im having the same ios issue with the Xamarin Forms sample

@Piguelo
Copy link

Piguelo commented Feb 22, 2023

Is @JimmyPun610 alive?

I'm facing the same issue, scan works on iphone 6 but crash on iphone 12 and 13

@JimmyPun610
Copy link
Owner

Please provide more information. E.g. logging, is it happening in Xamarin.Forms or Maui?
If the error log is similar to below

Could not create an native instance of the type....

You could try this...
For Xamarin Forms, does the iOS project architecture set to arm64 and linker behaviour to 'Dont link'

For Maui, please add these to project file

<RuntimeIdentifier>ios-arm64</RuntimeIdentifier>
<PlatformTarget>arm64</PlatformTarget>-->

@Piguelo
Copy link

Piguelo commented Feb 23, 2023

Updating to 6.3.0.25 resolved the issue. It's working in all devices now.

@midrpostcz
Copy link

Hi

In Android it works perfectly. Great. Thank you.

But I am also getting the error on iPhone for version 6.3.0.25:

[0:] An error occurred: 'Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded.
It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSObject2.cs:333
at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSObject2.cs:200
at MLKit.BarcodeScanning.BarcodeScannerOptions..ctor (MLKit.BarcodeScanning.BarcodeFormat formats) <0x13c53ae18 + 0x0000a> in <90562b0e59984f7194cd2e17f619776c>:0
at BarcodeScanner.Mobile.UICameraPreview+CaptureVideoDelegate..ctor (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer) <0x13c538910 + 0x000b4> in <48be292882a748efbf3c356a41443b36>:0
at BarcodeScanner.Mobile.UICameraPreview.Initialize (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer) <0x13af28e10 + 0x00142> in <48be292882a748efbf3c356a41443b36>:0
at BarcodeScanner.Mobile.UICameraPreview..ctor (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer, BarcodeScanner.Mobile.CameraFacing cameraFacing, BarcodeScanner.Mobile.CaptureQuality captureQuality) <0x13af27af8 + 0x00022> in <48be292882a748efbf3c356a41443b36>:0
at BarcodeScanner.Mobile.Renderer.CameraViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) <0x13af2e508 + 0x000e6> in <48be292882a748efbf3c356a41443b36>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00172] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:296
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283
at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283
at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240
at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119
at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51
at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:252
at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr)
at UIKit.UIViewController.get_View () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIViewController.g.cs:2910
at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:104
at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:120
at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240
at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:378
at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:353
at Xamarin.Forms.Platform.iOS.NavigationRenderer.b__47_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:239
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021
at (wrapper delegate-invoke) .invoke_void_object(object)
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSAction.cs:178
--- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,string[],intptr,intptr,intptr&)
at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIApplication.cs:57
at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIApplication.cs:92
at SampleApp.XF.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\michd\Downloads\BarcodeScanner.Mobile-master\SampleApp.XF\SampleApp.XF.iOS\Main.cs:17
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 '
The app has been terminated.

@JimmyPun610
Copy link
Owner

Hi

In Android it works perfectly. Great. Thank you.

But I am also getting the error on iPhone for version 6.3.0.25:

[0:] An error occurred: 'Could not create an native instance of the type 'MLKit.BarcodeScanning.BarcodeScannerOptions': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'. Callstack: ' at Foundation.NSObject.InitializeObject (System.Boolean alloced) [0x0002e] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSObject2.cs:333 at Foundation.NSObject..ctor (Foundation.NSObjectFlag x) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSObject2.cs:200 at MLKit.BarcodeScanning.BarcodeScannerOptions..ctor (MLKit.BarcodeScanning.BarcodeFormat formats) <0x13c53ae18 + 0x0000a> in <90562b0e59984f7194cd2e17f619776c>:0 at BarcodeScanner.Mobile.UICameraPreview+CaptureVideoDelegate..ctor (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer) <0x13c538910 + 0x000b4> in <48be292882a748efbf3c356a41443b36>:0 at BarcodeScanner.Mobile.UICameraPreview.Initialize (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer) <0x13af28e10 + 0x00142> in <48be292882a748efbf3c356a41443b36>:0 at BarcodeScanner.Mobile.UICameraPreview..ctor (BarcodeScanner.Mobile.Renderer.CameraViewRenderer renderer, BarcodeScanner.Mobile.CameraFacing cameraFacing, BarcodeScanner.Mobile.CaptureQuality captureQuality) <0x13af27af8 + 0x00022> in <48be292882a748efbf3c356a41443b36>:0 at BarcodeScanner.Mobile.Renderer.CameraViewRenderer.OnElementChanged (Xamarin.Forms.Platform.iOS.ElementChangedEventArgs1[TElement] e) <0x13af2e508 + 0x000e6> in <48be292882a748efbf3c356a41443b36>:0 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x00172] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:296 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.VisualElementRenderer1[TElement].SetElement (TElement element) [0x0012e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:283 at Xamarin.Forms.Platform.iOS.VisualElementRenderer`1[TElement].Xamarin.Forms.Platform.iOS.IVisualElementRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementRenderer.cs:158 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.VisualElementPackager.OnChildAdded (Xamarin.Forms.VisualElement view) [0x0003e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:119 at Xamarin.Forms.Platform.iOS.VisualElementPackager.Load () [0x0001e] in D:\a\1\s\Xamarin.Forms.Platform.iOS\VisualElementPackager.cs:51 at Xamarin.Forms.Platform.iOS.PageRenderer.ViewDidLoad () [0x0008f] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:252 at (wrapper managed-to-native) ObjCRuntime.Messaging.IntPtr_objc_msgSendSuper(intptr,intptr) at UIKit.UIViewController.get_View () [0x0002a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIViewController.g.cs:2910 at Xamarin.Forms.Platform.iOS.PageRenderer.get_NativeView () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:104 at Xamarin.Forms.Platform.iOS.PageRenderer.SetElement (Xamarin.Forms.VisualElement element) [0x0003d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\PageRenderer.cs:120 at Xamarin.Forms.Platform.iOS.Platform.CreateRenderer (Xamarin.Forms.VisualElement element) [0x00032] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Platform.cs:240 at Xamarin.Forms.Platform.iOS.NavigationRenderer.CreateViewControllerForPage (Xamarin.Forms.Page page) [0x00008] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:378 at Xamarin.Forms.Platform.iOS.NavigationRenderer.OnPushAsync (Xamarin.Forms.Page page, System.Boolean animated) [0x0001d] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:353 at Xamarin.Forms.Platform.iOS.NavigationRenderer.b__47_0 (Xamarin.Forms.Page p) [0x00024] in D:\a\1\s\Xamarin.Forms.Platform.iOS\Renderers\NavigationRenderer.cs:239 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__7_0 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1021 at (wrapper delegate-invoke) .invoke_void_object(object) at Foundation.NSAsyncSynchronizationContextDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/Foundation/NSAction.cs:178 --- End of stack trace from previous location where exception was thrown ---

at (wrapper managed-to-native) UIKit.UIApplication.xamarin_UIApplicationMain(int,string[],intptr,intptr,intptr&) at UIKit.UIApplication.UIApplicationMain (System.Int32 argc, System.String[] argv, System.IntPtr principalClassName, System.IntPtr delegateClassName) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIApplication.cs:57 at UIKit.UIApplication.Main (System.String[] args, System.Type principalClass, System.Type delegateClass) [0x0003b] in /Library/Frameworks/Xamarin.iOS.framework/Versions/16.2.0.5/src/Xamarin.iOS/UIKit/UIApplication.cs:92 at SampleApp.XF.iOS.Application.Main (System.String[] args) [0x00001] in C:\Users\michd\Downloads\BarcodeScanner.Mobile-master\SampleApp.XF\SampleApp.XF.iOS\Main.cs:17 at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&) at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x0006a] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/corlib/System.Reflection/RuntimeMethodInfo.cs:395 ' The app has been terminated.

Hi, I have just done some research against this issue recently and it seems it has a possible workaround.
I guess you are using Windows and deploy to iPhone with Pair-to-Mac features and hot-restart.

To be short, you may try to copy the code from https://gist.github.com/mattjohnsonpint/37d3ac06a563c41618fc933bf7282d66 to your maui project .csproj, paste it with the and try to rebuild it again. Or as an alternative, build and deploy to iOS directly by the latest Visual studio for Mac.

For others related articles, please see if below could help you....
dotnet/maui#10800 (comment)
https://supportcenter.devexpress.com/ticket/details/t1121521/maui-the-could-not-create-an-native-instance-error

Any feedback would be appreciate

@midrpostcz
Copy link

Hi
Thank you for your support.
I directly deploy from Windows to iOS local device (not Pair to Mac or Remote Device).
I tried that workabout but did not solve the problem.
This will probably be the problem. I faced may be something very similar to this when I was using maps from Google.
I will use VS on my Mac instead.
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

9 participants