I am trying to extract the X509 certificate off of my Yubikey's PIV programmatically. I am using .NET Standard 2.0 on Windows 10, and I am trying to install and use the Yubico SDK Nuget package (Yubico.Yubikey 1.3.1). After installing the package and making sure the DLLs are being copied to my bin directory, I am running my application and trying to run the example code from the SDK User Guide
The first line of the example code is: Dim yubikey = YubiKeyDevice.FindAll().First
-- however on executing this first line I am getting an exception about a DLL that cannot be loaded.
System.DllNotFoundException: 'Unable to load DLL 'Yubico.NativeShims': The specified module could not be found. (Exception from HRESULT: 0x8007007E)'
Sure enough, there is no Yubikey.NativeShims DLL being copied to my bin directory (although I do have a Yubico.Core.dll, a Yubico.Yubikey.dll, and a Yubico.DotNetPolyfills.dll). Even after tracking down a copy of this missing DLL for my target platform, and putting it in the bin folder, I still get this exception.
What am I missing?
I have included the complete stack trace from the exception here:
at Yubico.PlatformInterop.NativeMethods.SCardEstablishContext(SCARD_SCOPE scope, SCardContext& context)
at Yubico.Core.Devices.SmartCard.DesktopSmartCardDeviceListener..ctor()
at Yubico.Core.Devices.SmartCard.SmartCardDeviceListener.Create()
at Yubico.YubiKey.YubiKeyDeviceListener..ctor()
at Yubico.YubiKey.YubiKeyDeviceListener.<>c.<.cctor>b__34_0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at Yubico.YubiKey.YubiKeyDeviceListener.get_Instance()
at Yubico.YubiKey.YubiKeyDevice.FindByTransport(Transport transport)
at Yubico.YubiKey.YubiKeyDevice.FindAll()
at ClassLibrary1.Class1.Work() in C:\Users\jzylkin\source\repos\WindowsApp3\ClassLibrary1\Class1.vb:line 6
at WindowsApp3.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\jzylkin\source\repos\WindowsApp3\WindowsApp3\Form1.vb:line 6
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Here is the vbproj project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>ClassLibrary1</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
<CopyLocalLockFileAssemblies>True</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Yubico.YubiKey" Version="1.3.1" />
</ItemGroup>
</Project>
Jack,
I pumped in the similar problem. I just renamed Yubico.NativeShims.dll to Yubico.NativeShims (just remove .dll extension) and it worked.
Sharon