Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Dependency Exception in PowerShell 7.4.6 #184

Open
1 task done
htcfreek opened this issue Jan 2, 2025 · 6 comments
Open
1 task done

[BUG] Dependency Exception in PowerShell 7.4.6 #184

htcfreek opened this issue Jan 2, 2025 · 6 comments
Labels
bug Something isn't working

Comments

@htcfreek
Copy link

htcfreek commented Jan 2, 2025

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

PS C:\Users\xxx>  cd C:\Users\xxx\Downloads\test\1-12-1-4.7.2\
PS C:\Users\xxx\Downloads\test\1-12-1-4.7.2> Add-Type -Path .\Yubico.Yubikey.dll
PS C:\Users\xxx\Downloads\test\1-12-1-4.7.2> [Yubico.Yubikey.YubikeyDevice]::FindAll()
MethodInvocationException: Exception calling "FindAll" with "0" argument(s): "Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.1, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Das System kann die angegebene Datei nicht finden."

Expected Behavior

The properties of all connected devices are shown.

Steps To Reproduce

  1. Install Pwsh 7.4.6 and download your sadk.
  2. Export your SDK.
  3. Load your SDK in PowerShell.
  4. Run command [Yubico.Yubikey.YubikeyDevice]::FindAll()

Version

1.12.1

Version

???

Anything else?

PS C:\Users\xxx> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.6
PSEdition                      Core
GitCommitId                    7.4.6
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

PS C:\Users\xxx> [System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription
.NET 8.0.10
@htcfreek htcfreek added the bug Something isn't working label Jan 2, 2025
@GregDomzalski
Copy link
Contributor

The YubiKey SDK has a dependency on a native shared library: Yubico.NativeShims.dll

Unfortunately, the way that NuGet packages and PowerShell modules handle these kinds of dependencies are different. The recommended folder structure for PowerShell 7.4 is documented here: https://learn.microsoft.com/en-us/powershell/scripting/dev-cross-plat/writing-portable-modules?view=powershell-7.4&viewFallbackFrom=powershell-7#dependency-on-native-libraries

For background, this is how .NET and NuGet handle it: https://learn.microsoft.com/en-us/nuget/create-packages/native-files-in-net-packages

You will need to translate the folder structure of the Yubico.NativeShims.nupkg into the structure expected by PowerShell as documented above.

@htcfreek
Copy link
Author

htcfreek commented Jan 2, 2025

Again: Where to download this file. It is not part of the assets.

@GregDomzalski
Copy link
Contributor

Which NuGet packages have you downloaded?

You will need:

A nupkg file is simply a zip file with extra metadata. If you rename each file from *.nupkg to *.zip you should be able to extract the shared libraries from there.

Yubico.YubiKey, Yubico.Core, and Yubico.DotnetPolyfills should each be extracted to your module directory as they are all managed / .NET libraries.

Within the extracted folder for Yubico.NativeShims you should see the runtimes folder which will have all of the various native versions of this library. (You can see this here: https://nuget.info/packages/Yubico.NativeShims/1.12.1)

@htcfreek
Copy link
Author

htcfreek commented Jan 2, 2025

Wow. I used the assets from github release. And there the NativeShims are missing since a few releases.

I will try later again withe the other downloads.

@GregDomzalski
Copy link
Contributor

GregDomzalski commented Jan 2, 2025

Got it. Even though NativeShims is part of this repo, since it does not change as often - and quite frankly, is complex to build and sign - it is typically not re-released with each version of the SDK. At least not on GitHub. Since .NET's typical consumption route is NuGet, that is where the focus is spent on releasing assets.

But adding all libraries to each GitHub release page, regardless of update, can be something @DennisDyallo and @dainnilsson evaluate as part of their release process.

@htcfreek
Copy link
Author

htcfreek commented Jan 2, 2025

@GregDomzalski
I found the problem and it is not the Native.Shim.dll. The problem are missing Microsoft .Net dependencies. If I provide the DLL from the nuget package of 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0 then the error is gone and an other dependency is requested ('Microsoft.Extensions.Configuration, Version=8.0.0.0). SO there seems to be a problem loading the required .Net assemblies.

Did you specified fixed version in the project dependencies? (PowerShell/vscode-powershell#4475)

And by the way, version 1.0.0 of your SDK works fine in PowerShell 7.4.6. But is a bit old for using it.

Error before adding MS assembly:

PS $> [Yubico.Yubikey.YubikeyDevice]::FindAll()
MethodInvocationException: Exception calling "FindAll" with "0" argument(s): "Could not load file or assembly 'Microsoft.Extensions.Logging.Abstractions, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system can not find the specified file."

After providing the file:

PS C:\Users\xxx\Downloads\yubiky-sdk_1.12.1_netStd21> dir -name -Recurse
Microsoft.Extensions.Logging.Abstractions.dll
Microsoft.Extensions.Logging.dll
Yubico.Core.dll
Yubico.DotNetPolyfills.dll
Yubico.YubiKey.dll
win-x64\Yubico.NativeShims.dll
win-x86\Yubico.NativeShims.dll
PS $> [Yubico.Yubikey.YubikeyDevice]::FindAll()
MethodInvocationException: Exception calling "FindAll" with "0" argument(s): "Could not load file or assembly 'Microsoft.Extensions.Configuration, Version=8.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system can not find the specified file."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

2 participants