FileNotFoundException When Reading SmartCard ID
Hello,
I'm working on an application that needs to read the id of smartcards to check people into meetings.
Working in WPF with .NET 4.7.2 and using the Windows API to read the cards (Windows.Devices.SmartCards). Piecing together what needs to be done to read it, I've come to the following flow:
- find readers on application startup and add an event handler for CardAdded
- in the handler, get the SmartCardProvisioning for the SmartCard provided by the event.
- attempt to read the card id with SmartCardProvisioning.GetIdAsync
When calling GetIdAsync, a FileNotFoundException is raised. I've tried printing the FileName that it's attempting to open to no avail.
Information on this is scarce, and any help is appreciated.
30 Replies
Any details of the error?
Also please upload the code when asking a question $paste
If your code is too long, you can post to https://paste.mod.gg/, save, and copy the link into chat for others to see your shared code!
BlazeBin - bwrvaoxdnnmb
A tool for sharing your source code with the world!
Reader is recognized and the event is called. Scanning cards results in the following popup:

you can set a breakpoint in the catch block and look at the exception

Try using a 3rd party library, such as https://www.nuget.org/packages/PCSC
Note that I have not tried it, so it may not even work.
I don't see why this shouldn't work using the native APIs that are exposed.
tried running it as admin?
I saw someone else had the same issue.
https://stackoverflow.com/questions/18682677/how-to-get-id-using-smartcardprovisioning-getidasync-windows-device-smartcards
No responses on it and it was made in 2013
I have tried this, yes.
I've also tried publishing the code, moving it to a clean computer and installing it
and running it there. The same error occurs.
Came across this in my searching, but not much of a help considering the dead link provided.
Right, my point exactly.
There's not much information about it.
I'd rather try another library to see if that works instead.
https://learn.microsoft.com/en-us/uwp/api/windows.devices.smartcards.smartcardprovisioning.getidasync?view=winrt-26100 am i on the right docs?
is this winrt only?
SmartCardProvisioning.GetIdAsync Method (Windows.Devices.SmartCards...
Returns the smart card's ID.
Those would be the correct docs. From what I've seen this API should be compatible with the tools I'm trying to use.
All steps up to reading the Id off the card perform as expected.
A quick search for FileNotFoundException coming from mscordlib led me to this
So running through that now just in case, although I have little hope as it happens on a fresh install as well so
dont get your hopes up.. this is more or less the default answer on that page
(I've never had sfc fix an issue in my life)
more likely that the interop return hresult 0x80070002 which got translated to that exception
not much found how that event is used either https://grep.app/search?q=CardAddedEventArgs
Code Search | Grep by Vercel
Search for code, files, and paths across half a million public GitHub repositories.
I've attempted this same flow but without utilizing the event as well.
Via
SmartCardReader.FindAllCardsAsync
and having the card on the reader at the time the code is started
I know it isn't an issue with the cards (I've tried two different ones) because they read fine in the omnikey workbench util
I've tried this with two different models of HID Omnikey readersmaybe more info in the event viewer
No logged events from what I can see.
I impl. a smartcard api for egks. To read the data u need to work with APDU commands. When u get the byte string u need to convert it into an string and then convert it into an object
For the card reader events i used pcsc
I'll try to write this using pcsc and see if the results come back different. Very strange that a high level API like this directly from MS doesn't behave like expected
normally u have for the terminal a doc where the apdu commands are specified
what terminal r u using?
HID OMNIKEYs
There's two models, I'd have to pull up the PO as I'm not on site rn
okay okay
HID OMNIKEY 5427ck Gen 2
HID OMNIKEY 5025 CL
are the two models in hand
Yeah its like i said, u need to communicate with apdu commands/responses
U need to find the commands of the card reader and impl. it with the pcsc libr.
I'll have a go with it next week. I appreciate the help.
np