System.DllNotFoundException:libpcsclite.so.1 程序集:<unknown assembly> 类型:<unknown type> 成员:(空)

System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)

多次研究这个问题,但没有找到解决方案。使用 xamarin 表单版本 5.0.0.2012,在 win 10 os 上(看到许多 mac 或 linux 的解决方案,但没有找到 windows 的任何解决方案),使用 PCSC 库版本 5.0.0。在 Android 8.0:

上调试时尝试调用 context.Establish 方法
    public SimpleReader(ISCardContext context, bool releaseContextOnDispose = false)
    {
        if (context == null)
        {
            context = (ISCardContext) new SCardContext();
            context.Establish(SCardScope.System);
            releaseContextOnDispose = true;
        }

        this._context = context;
        this._reader = (ISCardReader) new SCardReader(context);
        this._releaseContextOnDispose = releaseContextOnDispose;
        this._disconnectReaderOnDispose = true;
    }

何时,出现以下消息的异常:

System.DllNotFoundException: libpcsclite.so.1 assembly:<unknown assembly> type:<unknown type> member:(null)
  at (wrapper managed-to-native) PCSC.Interop.Linux.LinuxNativeMethods.SCardEstablishContext(intptr,intptr,intptr,intptr&)
  at PCSC.Interop.Linux.PCSCliteLinux.EstablishContext (PCSC.SCardScope dwScope, System.IntPtr pvReserved1, System.IntPtr pvReserved2, System.IntPtr& phContext) [0x00006] in C:\Users\danm\src\pcsc-sharp\src\PCSC\Interop\Linux\PCSCliteLinux.cs:39 
  at PCSC.SCardContext.Establish (PCSC.SCardScope scope) [0x00020] in C:\Users\danm\src\pcsc-sharp\src\PCSC\SCardContext.cs:81 
  at App1xx.Services.SimpleReader.SimpleReader..ctor (PCSC.ISCardContext context, System.Boolean releaseContextOnDispose) [0x00023] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:59 
  at App1xx.Services.SimpleReader.SimpleReader..ctor () [0x00000] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\SimpleReaderLib\SimpleReader.cs:70 
  at App1xx.Services.UaIdRLib.IdCardReader.connect () [0x00002] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Services\UaIdRLib\IdCardReader.cs:371 
  at App1xx.Views.AboutPage.OnButtonClicked (System.Object sender, System.EventArgs args) [0x0000f] in C:\Users\vzhynkin\source\repos\App1xx\App1xx\App1xx\Views\AboutPage.xaml.cs:22 
  at Xamarin.Forms.Button.Xamarin.Forms.Internals.IButtonElement.PropagateUpClicked () [0x00000] in D:\a\s\Xamarin.Forms.Core\Button.cs:187 
  at Xamarin.Forms.ButtonElement.ElementClicked (Xamarin.Forms.VisualElement visualElement, Xamarin.Forms.Internals.IButtonElement ButtonElementManager) [0x0001f] in D:\a\s\Xamarin.Forms.Core\ButtonElement.cs:61 
  at Xamarin.Forms.Button.SendClicked () [0x00000] in D:\a\s\Xamarin.Forms.Core\Button.cs:173 
  at Xamarin.Forms.Platform.Android.ButtonElementManager.OnClick (Xamarin.Forms.VisualElement element, Xamarin.Forms.IButtonController buttonController, Android.Views.View v) [0x00000] in D:\a\s\Xamarin.Forms.Platform.Android\ButtonElementManager.cs:25 
  at Xamarin.Forms.Platform.Android.FastRenderers.ButtonRenderer.Android.Views.View.IOnClickListener.OnClick (Android.Views.View v) [0x00000] in D:\a\s\Xamarin.Forms.Platform.Android\FastRenderers\ButtonRenderer.cs:72 
  at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x00010] in /Users/builder/azdo/_work/278/s/xamarin-android/src/Mono.Android/obj/Release/monoandroid10/android-30/mcw/Android.Views.View.cs:2252 
  at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.68(intptr,intptr,intptr)

有人遇到过这个问题吗?

PCSC 库似乎没有明确支持 Android。根据我的经验,使用 Xamarin.Android 的 nugets 为平台设置了明确的依赖关系,但是 this one does not.

该库尝试使用 P/Invoke 包装本机代码。可以看到有implementations for a number of operating systems here, but I don't see any references to Android. The stack trace shows that the code is deciding to use the Linux wrapper, which makes sense. It's looking for the libpcsclite.so.1 native "C/C++" library, but it's not finding it. That library has a home page that does not reference Android.

PCSC nuget docs状态:

pcsc-sharp does not contain any device drivers. A PC/SC compliant reader + driver is mandatory.

那就是 libpcsclite.so.1 。您的 Android 设备不提供它,或者如果提供,它不在您的 Android 应用可以找到它的位置。我的 Android 设备 (运行 Android 9) 在任何 /system/*lib* 目录中都没有该库,这意味着至少对于我的设备,有人需要编译它设备的 CPU(通常是 arm64)的本机库。如果您可以自己编译本机代码或找到拥有 AND 本机代码支持 Android 设备上的 reader 的人,那么您可以获得整个工作。

我自己对 PCSC 没有任何经验 - 只有一些 Xamarin 和本机库的经验。