ZXing 无法在 iOS 的 Xamarin Forms 中加载类型

ZXing Could not load Type in Xamarin Forms for iOS

我在我的 Xamarin Forms 应用程序中遇到错误。此错误仅发生在 Android。 iOS 工作正常。

这是抛出异常的行。

ZXing.Net.Mobile.Forms.Android.Platform.Init();

这是例外

Could not load typeZXing.Net.Mobile.Forms.Android.ZXingScannerViewRenderer'
from assembly 'ZXing.Net.Mobile.Forms.Android, Version=2.1.47.0,
Culture=neutral, PublicKeyToken=null'.

StackTrance:

at ZXing.Net.Mobile.Forms.Android.Platform.Init () [0x00000] in <30849edafd8e4fbb9f24af588a9bebb0>:0 
at AllergyDetector.Droid.MainActivity.OnCreate (Android.OS.Bundle bundle) [0x0002d] in /Users/alexanderrummel/Development/Projects/dotNet/AllergyDetector/Droid/MainActivity.cs:28 
at Android.Support.V4.App.FragmentActivity.n_OnCreate_Landroid_os_Bundle_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_savedInstanceState) [0x00011] in <27c17fe440cf491ba8255bcefade6e02>:0 
at (wrapper dynamic-method) System.Object:ceddf78a-cf9a-4fee-97a9-ea86e17b2375 (intptr,intptr,intptr)

我使用以下版本

XamarinForms: 2.3.3.152-pre2
ZXing.Net.Mobile 2.1.47
ZXing.Net.Mobile.Forms 2.1.47

TargetFramework Android 5.0
MinimalAndroid Version Android 5.0

经过快速 Google 操作后,这似乎是 Xamarin.Forms 2.3.3.152-pre2 版本的一个已知问题。看看 GitHub 页面 here 虽然它似乎也发生在其他版本的 Xamarin.Forms.

还有一个由 richardpike 建议的修复:

I was able to fix this for myself by downloading the source code and updating the xamarin forms package to the pre-release (2.3.3.152-pre2)

This required 2 new override functions in ZXingScannerViewRenderer.cs, and ZXingBarcodeImageViewRenderer.cs (from the ZXing.Net.Mobile.Forms.Android project). All I did was make them return null.

This builds successfully and I was able to use the resulting dll in my project without it crashing.

I would make a pull request, but I've never done one before using github...

如果您对此不满意,恐怕您只能等待他们解决此问题。