Search code examples
.netuwpdllimportpcsc

winscard.dll not supported for UWP (System.TypeLoadException using pcsc-sharp library)


I am trying to use v4 of pcsc-sharp library within a UWP application https://github.com/danm-de/pcsc-sharp

I understand with v4, pcsc-sharp is now on .net standard 2.0 which UWP supports.

Good news is that we are able to Transmit CommandApdu and read public data of a ISO7816 smart card. The bad news is that this seems to work only in debug mode and when run in release mode, we get the following error:

Exception Details

{System.TypeLoadException: Unresolved P/Invoke method 'winscard.dll!SCardEstablishContext' from this method. Please look for this method in build warnings for more details.

Build warnings

Warning MCG : warning MCG0007: Unresolved P/Invoke method 'winscard.dll!SCardSetAttrib' for method 'System.Int32 PCSC.Interop.Windows.WinSCardAPI.SCardSetAttrib(System.IntPtr, System.Int32, System.Byte[], System.Int32)'. Calling this method would throw exception at runtime.

Please make sure the P/Invoke either points to a Windows API allowed in UWP applications, or a native DLL that is part of the package. If for some reason your P/Invoke does not satisfy those requirements, please use [DllImport(ExactSpelling=true) to indicate that you understand the implications of using non-UWP APIs.

How do you read into this ? Am I trying to do the impossible here ?

Incidentally, I have tried to enable .net native tool chain in debug mode. thats how I got these exception details. I also tried to run in both x64 and x86 modes but it aint working either way. it works in debug mode only when .net native toolchain is not checked in the project properties.

According to the error we have to do DllImport to call those methods, but in the code of pcsc-sharp we already have all those Dll import stuff on the methods we r trying to call. so it doesn't make sense why it is still giving us those errors.

Github issue : https://github.com/danm-de/pcsc-sharp/issues/70


Solution

  • Unfortunately, WinScard.dll is not currently supported for UWP. If there are features missing from the SmartCard API, you can send feedback via UserVoice or the Feedback Hub.