-
Notifications
You must be signed in to change notification settings - Fork 225
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
Import-Module : Could not load file or assembly Microsoft.Bcl.AsyncInterfaces #558
Comments
I confirm, we face the same issue on Linux (Ubuntu 20.04 LTS)
Tested with
|
When you look at the $error what does the loadexception says? Sent from my iPhoneOn Jan 4, 2024, at 6:12 AM, DuyHai DOAN ***@***.***> wrote:
I confirm, we face the same issue
FileLoadException: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
Tested with
Posh-SSH v 3.1.1
Posh-SSH v 3.1.2
Powershell Core 7.4.0
Powershell Core 7.5.0
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Here is my test code Write-Host "*** Installing Posh SSH Module 3.1.2 ***"
Install-Module -Name Posh-SSH -Force -RequiredVersion 3.1.2
Write-Host "*** Import Posh SSH Module ***"
try {
Import-Module Posh-SSH
} catch {
Write-Host "error = $($Error | Out-String)"
} And here is the display
|
I unlisted the module. It seems the last SSH.Net update added a dependency, so I can make it only work with one or the other at the moment. sshnet/SSH.NET#1287 |
(I know nothing about powershell modules) Is it possible to package Microsoft.Bcl.AsyncInterfaces.dll alongside Renci.SshNet.dll? |
Will you do a new release for the fix ? Regards |
I did and I get error’s depending on the version of .net used still trying to figure what broken with this latest nugget Sent from my iPhoneOn Jan 4, 2024, at 8:01 AM, Rob Hague ***@***.***> wrote:
(I know nothing about powershell modules) Is it possible to package Microsoft.Bcl.AsyncInterfaces.dll alongside Renci.SshNet.dll?
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>
|
If I can fix it, seems the dependency messes stuff up when running under .ner standard 2.0
|
I copied the files straight from the .Netstandard 2.0 nugget for the library it will not even let me load it by hand |
Where is Renci.SshNet.dll and SshNet.Security.Cryptography.dll? Should Microsoft.Bcl.AsyncInterfaces.dll be alongside those? |
all of the files from the dependecies json file
|
the .net standard 2.0 files load no problems under PS version 5.1
|
Any more error details from |
|
The HResult is 0x80131621 which has a few results on google, including pnp/powershell#1814 Perhaps there is some conflict somewhere. Does this show anything?
|
Tried it at startup, after loading SSH.NET, after importing the module. Seems to error when it is actually used. DLL is in the same directory ╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 10:10:21
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:14:26
╰─❯ Add-Type -Path .\Renci.SshNet.dll
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:01
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:03
╰─❯ import-module -verbose .\PoshSSH.dll
VERBOSE: Importing cmdlet 'Get-SSHHostKey'.
VERBOSE: Importing cmdlet 'Get-SCPItem'.
VERBOSE: Importing cmdlet 'Get-SFTPItem'.
VERBOSE: Importing cmdlet 'New-SFTPSession'.
VERBOSE: Importing cmdlet 'New-SSHSession'.
VERBOSE: Importing cmdlet 'Set-SCPItem'.
VERBOSE: Importing cmdlet 'Set-SFTPItem'.
VERBOSE: Importing cmdlet 'New-SSHMemoryKnownHost'.
VERBOSE: Importing cmdlet 'Get-SSHJsonKnownHost'.
VERBOSE: Importing cmdlet 'Get-SSHOpenSSHKnownHost'.
VERBOSE: Importing alias 'Get-SSHJsonKnowHost'.
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:31
╰─❯ New-SSHSession v0.local pi
PowerShell credential request
Enter your credentials.
Password for user pi: ********
New-SSHSession: Could not load file or assembly 'Microsoft.Bcl.AsyncInterfaces, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Could not find or load a specific file. (0x80131621)
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 11:15:41
╰─❯ [System.AppDomain]::CurrentDomain.GetAssemblies() | Where-Object {$_.FullName -match "Microsoft.Bcl.AsyncInterfaces"} | Select-Object -Property
FullName, Location | fl
╭─ pwsh ~\Documents\GitHub\Posh-SSH\Posh-SSH master ?9 ~1 |
I set on the project true to have it bundle all dependencies and still not working on PS7, it has to be some bug or something changed in PS. I did notice that when I look at [System.AppDomain]::CurrentDomain.GetAssemblies() | where {$_.location -like "user"} I see the module is loaded and SSH.Net assembly, but if I look at all assemblies some are blank for some reason |
Now I'm completely lost. I can load it by hand, it is in the CAG but it can not find it .. .
|
I have a C:\Program Files\PowerShell\7\Microsoft.Bcl.AsyncInterfaces.dll which is version 5.0.0.0 The problem could be that the SSH.NET nuspec defines an exact dependency (with square brackets) on 8.0.0 and because PS7 has a dependency on a different version already, it refuses to load another. You could try the following diff in SSH.NET: diff --git a/src/Renci.SshNet/Renci.SshNet.csproj b/src/Renci.SshNet/Renci.SshNet.csproj
index 877b3b89..334df508 100644
--- a/src/Renci.SshNet/Renci.SshNet.csproj
+++ b/src/Renci.SshNet/Renci.SshNet.csproj
@@ -14,7 +14,7 @@
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' or '$(TargetFramework)' == 'netstandard2.0' ">
- <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="8.0.0" />
+ <PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.0.0" /> <!-- or a higher version -->
</ItemGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' or '$(TargetFramework)' == 'netstandard2.1' or '$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0' or '$(TargetFramework)' == 'net8.0' ">
and try again with a local build of the library. If things are still not getting anywhere, I would be in favour of removing the dependency from the library to unblock your module. It is not a necessary part of the library. cc @WojciechNagorski |
@Rob-Hague Thanks!! it worked now on both versions of PS, I will do more tests before I update my module |
Great It would be useful if you could do a quick check with a local build using version 8.0.0 and see whether it still works (which would imply the problem would be fixed by sshnet/SSH.NET#1288), or if it only works with a version <= 5.0.0 or whatever PS7 seems to be using (in which case, we should probably remove the dependency altogether) |
@darkoperator @Rob-Hague I'm confused. If the csproj diff fixes it, wouldn't this mean the problem is version 8.0.0? In this case sshnet/SSH.NET#1288 wouldn't fix it, since SSH.NET would still need 8.0.0 (it would just also accept 9.0 etc.). If PowerShell can't handle the newer Microsoft.Bcl.AsyncInterfaces Version for whatever reason, it would probably be best for SSH.NET to require >=1.0.0 instead >=8.0.0 . I doubt that SSH.NET actually needs an up-to-date version since it's just a compat package for .NET Framework / .NET Standard. |
yep, with version 1.1.0 it worked in terms of loading and establishing a SSH connection. Version 8.0.0 loading was the version causing the problem in PS 7 |
Can you prepare a PR? |
I think this one is covering it sshnet/SSH.NET#1288 |
@mus65 I'm not so clear on the nuances of dll loading 🙂 Can you can modify your PR to take version >= 1.0.0? |
This technically fixes 2 different issues: - previously SSH.NET would require exactly(!) version 8.0.0, which would cause issues in the future if e.g. a project using SSH.NET would try to update to version 9.0.0. In this case the constraint on the exact version would cause NuGet to refuse to upgrade to 9.0.0 (sshnet#1287) - PowerShell Core seems to have problems with Version 8.0.0, therefore downgrade the requirement to 1.0.0 (see darkoperator/Posh-SSH#558)
@WojciechNagorski @Rob-Hague @darkoperator I updated my PR to fix both issues: sshnet/SSH.NET#1288 |
This technically fixes 2 different issues: - previously SSH.NET would require exactly(!) version 8.0.0, which would cause issues in the future if e.g. a project using SSH.NET would try to update to version 9.0.0. In this case the constraint on the exact version would cause NuGet to refuse to upgrade to 9.0.0 (sshnet#1287) - PowerShell Core seems to have problems with Version 8.0.0, therefore downgrade the requirement to 1.0.0 (see darkoperator/Posh-SSH#558) I had to re-enable AutoGenerateBindingRedirects, otherwise there is a FileLoadException with net462 in one of the tests. I don't know why this was disabled in 3ecbd10 .
This technically fixes 2 different issues: - previously SSH.NET would require exactly(!) version 8.0.0, which would cause issues in the future if e.g. a project using SSH.NET would try to update to version 9.0.0. In this case the constraint on the exact version would cause NuGet to refuse to upgrade to 9.0.0 (#1287) - PowerShell Core seems to have problems with Version 8.0.0, therefore downgrade the requirement to 1.0.0 (see darkoperator/Posh-SSH#558) I had to re-enable AutoGenerateBindingRedirects, otherwise there is a FileLoadException with net462 in one of the tests. I don't know why this was disabled in 3ecbd10 .
@darkoperator PowerShell distributes Microsoft.Bcl.AsyncInterfaces, so if you want to load another version, that creates a conflict. Every time the PowerShell team changes the version of this assembly, it will break your module. The technical explanation is here: In the quick version (this is contained in the previous document), if you define a class that implements IModuleAssemblyInitializer , when the module loads, you can insert code that allows you to load a library with the version of your choice (via an AssemblyLoadContext) I'm giving you the repository of the person who worked on the subject at the time (same use case as the doc) A random example : https://github.com/PSBicep/BicepNet/blob/main/BicepNet.PS/LoadContext/ModuleInitializer.cs |
Hello @darkoperator Any update on the fix ? Should I use the latest release of the module ? |
You can use the latest available in the gallery, at the moment waiting to see when they will push a new nugget with the fixed version. If in a couple of weeks they do not push one I will push my own version by compiling from the development branch.
|
@doanduyhai can you give the pre-release a test https://github.com/darkoperator/Posh-SSH/releases/tag/3.1.3-Beta1 |
Hello @darkoperator I'll be happy to test the Beta release However, because I'm a newbie in Powershell and .Net environment, I don't know how to use your beta package in .zip release form Usually, to install a Powershell module, I just use the command Please give me instructions on how to deploy the zip file and I'll be happy to test it Regards |
1. Download the zip file
2. Right click on it go to properties and check the box for unblock.
3. Decompress
4. Open PS and navigate to the folder where the psd1 file for the decompressed module is located
5. Import-module .\posh-ssh.psd1 -verbose
|
Here is what I get Source code: Write-Host "****** Loading Posh-SSH beta version ********"
Import-Module -Name /_redacted_/posh-ssh-binaries/Posh-SSH -Verbose
Result:
|
Integration test with a real SFTP endpoint Source: Write-Host "Downloading secret 'private-ssh-key' from KeyVault '__redacted__' to local private.pem file"
az keyvault secret download `
--vault-name "__redacted__" `
--name "sftp-private-ssh-key" `
--file ./private.pem `
--encoding ascii
$username="__redacted__"
$password = ""
$secureStringPwd = $password | ConvertTo-SecureString -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $username, $secureStringPwd
try {
$blobEndpoint = "__redacted__"
Write-Host "Connecting to SFTP endpoint '$blobEndpoint' with user '$username'"
$currentSession=New-SFTPSession `
-Computername "$blobEndpoint" `
-Credential $credential `
-KeyFile ./private.pem `
-AcceptKey `
-Force
} finally {
if($currentSession -ne $null) {
Write-Host "Disconnecting SFTP session from host '$blobEndpoint'"
Remove-SFTPSession $currentSession
}
if (Test-Path "./private.pem") {
Write-Host "Removing local 'private.pem' file"
Remove-Item "./private.pem"
}
} Result:
|
Thanks, was this by any chance against a Cisco device?
|
No, I was testing against an Azure Storage Account with SFTP feature enabled |
I was experiencing this issue in an Azure Function running Powershell 7. Setting the required version of this module to the new beta release resolved the issue. |
Is this fixed in version |
Yes, need to pusblish the zipSent from my iPhoneOn Jan 30, 2024, at 10:16 AM, DarkLite1 ***@***.***> wrote:
Is this fixed in version Posh-SSH 3.1.3? That's the current version in the PowerShell gallery but that version is marked here on GitHub as being Beta.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
This technically fixes 2 different issues: - previously SSH.NET would require exactly(!) version 8.0.0, which would cause issues in the future if e.g. a project using SSH.NET would try to update to version 9.0.0. In this case the constraint on the exact version would cause NuGet to refuse to upgrade to 9.0.0 (#1287) - PowerShell Core seems to have problems with Version 8.0.0, therefore downgrade the requirement to 1.0.0 (see darkoperator/Posh-SSH#558) I had to re-enable AutoGenerateBindingRedirects, otherwise there is a FileLoadException with net462 in one of the tests. I don't know why this was disabled in 3ecbd1071d653bbf04254c08d14d7ce75d60688b .
I have this error only on PowerShell Core and not on Windows PowerShell 5.1
It was working fine until the latest release...
Here is my PowerShell configuration:
The text was updated successfully, but these errors were encountered: