C
C#4w ago
fretgfr

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
Buddy
Buddy4w ago
Any details of the error? Also please upload the code when asking a question $paste
MODiX
MODiX4w ago
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!
fretgfr
fretgfrOP4w ago
BlazeBin - bwrvaoxdnnmb
A tool for sharing your source code with the world!
fretgfr
fretgfrOP4w ago
Reader is recognized and the event is called. Scanning cards results in the following popup:
No description
Sehra
Sehra4w ago
you can set a breakpoint in the catch block and look at the exception
fretgfr
fretgfrOP4w ago
No description
Buddy
Buddy4w ago
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.
fretgfr
fretgfrOP4w ago
I don't see why this shouldn't work using the native APIs that are exposed.
ACiDCA7
ACiDCA74w ago
tried running it as admin?
Buddy
Buddy4w ago
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
fretgfr
fretgfrOP4w ago
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.
Buddy
Buddy4w ago
Right, my point exactly. There's not much information about it. I'd rather try another library to see if that works instead.
fretgfr
fretgfrOP4w ago
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
ACiDCA7
ACiDCA74w ago
dont get your hopes up.. this is more or less the default answer on that page
fretgfr
fretgfrOP4w ago
(I've never had sfc fix an issue in my life)
Sehra
Sehra4w ago
more likely that the interop return hresult 0x80070002 which got translated to that exception
Sehra
Sehra4w ago
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.
fretgfr
fretgfrOP4w ago
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 readers
Sehra
Sehra4w ago
maybe more info in the event viewer
fretgfr
fretgfrOP4w ago
No logged events from what I can see.
taner.
taner.4w ago
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
fretgfr
fretgfrOP4w ago
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
taner.
taner.4w ago
normally u have for the terminal a doc where the apdu commands are specified what terminal r u using?
fretgfr
fretgfrOP4w ago
HID OMNIKEYs There's two models, I'd have to pull up the PO as I'm not on site rn
taner.
taner.4w ago
okay okay
fretgfr
fretgfrOP4w ago
HID OMNIKEY 5427ck Gen 2 HID OMNIKEY 5025 CL are the two models in hand
taner.
taner.4w ago
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.
fretgfr
fretgfrOP4w ago
I'll have a go with it next week. I appreciate the help.
taner.
taner.4w ago
np

Did you find this page helpful?