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

Assembly with same name is already loaded #595

Open
DarkLite1 opened this issue Sep 23, 2024 · 3 comments
Open

Assembly with same name is already loaded #595

DarkLite1 opened this issue Sep 23, 2024 · 3 comments

Comments

@DarkLite1
Copy link

DarkLite1 commented Sep 23, 2024

Since updating to 3.2.4 we often see this error:

The 'New-SFTPSession' command was found in the module 'Posh-SSH', but the module could not be loaded due to the following error: [Assembly with same name is already loaded] For more information, run 'Import-Module Posh-SSH'.

We run code in parallel:

@('path1','path2','path3')  | ForEach-Object -Parallel {
    New-SFTPSession -ComputerName 'PC1' -Credential $cred
}

This happens quite often. Is there something we're missing?

We never use Import-Module and rely on auto loading of modules.

This happens on PowerShell 7.4.5. We had to revert back to 3.2.1 where we don't have this issue.

@darkoperator
Copy link
Owner

In the $error[0] variable does it provide more info on what assembly is causing the issue?

@DarkLite1
Copy link
Author

DarkLite1 commented Oct 9, 2024

With the older version (3.2.1) we get this error, but not so often as the error in the OP on the newer version:

The 'New-SFTPSession' command was found in the module 'Posh-SSH', but the module could not be loaded. For more information, run 'Import-Module Posh-SSH'.

It's really hard to troubleshoot as it happens only a couple of times a day. It's probably an issue that happens when loading the assembly at the time the module is loaded from memory that makes it fail to load the New-SFTPSession CmdLet.

Maybe you can add more detailed error handling around the loading of the assemblies? So it spits out more details?

@DarkLite1
Copy link
Author

DarkLite1 commented Oct 9, 2024

It happens after this line:

VERBOSE: Loading module from path 'C:\Program Files\PowerShell\Modules\Posh-SSH\3.2.1\PoshSSH.dll'

When I run this code, the error shows up again:

$modulePath = 'C:\Program Files\PowerShell\Modules\Posh-SSH\3.2.1'
Add-Type -Path "$modulePath/PoshSSH.dll"

This code is included within in the module manifest file Posh-SSH.psd1:

# List of all files packaged with this module
FileList = @('Posh-SSH.psm1','PoshSSH.dll','Assembly\Newtonsoft.Json.dll','Assembly\Renci.SshNet.dll', 'Assembly\SshNet.Security.Cryptography.dll')

Is the PoshSSH.dll automatically lauded by PowerShell itself? Could the issue be within the DLL file? That it doesn't check whether it is already loaded or not, before loading again?

Looking at issue #284 it seems to be a bit related. However, running the code below does not generate an error at all:

$modulePath = 'C:\Program Files\PowerShell\Modules\Posh-SSH\3.2.1'
@(
    'Assembly\Newtonsoft.Json.dll',
    'Assembly\Renci.SshNet.dll',
    'Assembly\SshNet.Security.Cryptography.dll'
).ForEach(
    { Add-Type -Path "$modulePath/$_" }
)

image

image

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants