Session.Open() fails in PowerShell 7.0.0-preview.5

Advertisement

pit5123
Joined:
Posts:
2
Location:
Germany

Session.Open() fails in PowerShell 7.0.0-preview.5

Using WinSPC 5.15.5 on Windows 10 x64 Enterprise en-us 18363.449 the code:
# Load WinSCP .NET assembly
Add-Type -Path "WinSCPnet.dll"

# Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol              = [WinSCP.Protocol]::Sftp
    HostName              = "hostname.tld"
    UserName              = "uid"
    SshHostKeyFingerprint = "ssh-ed25519 256 XXX="
    SshPrivateKeyPath     = "path.ppk"
}

$sessionOptions.AddRawSettings("Compression", "1")
$sessionOptions.AddRawSettings("Cipher", "aes,blowfish,chacha20,WARN,3des,des,arcfour")
$sessionOptions.AddRawSettings("KEX", "ecdh,dh-group14-sha1,rsa,WARN,dh-gex-sha1,dh-group1-sha1")

$session = New-Object WinSCP.Session
$session.SessionLogPath = "d:\temp\erg.log"
try
{
    # Connect
    $session.Open($sessionOptions)

    # Your code
}
finally
{
    $session.Dispose()
}
that works in PowerShell 5 does give the the following error in PowerShell 7 Preview 5 when calling the $session.Open():
MethodInvocationException: Exception calling "Open" with "1" argument(s): "Method not found: 'Void System.Threading.EventWaitHandle..ctor(Boolean, System.Threading.EventResetMode, System.String, Boolean ByRef, System.Security.AccessControl.EventWaitHandleSecurity)'."

No log file is created.

The corresponding C# code does work on .Net Core 3.0.

Of cause I have no idea if the issue is on the PowerShell or WinSCP side.

I have just the feeling it would be easier to start here.

Reply with quote

Advertisement

pit5123
Joined:
Posts:
2
Location:
Germany

Resolved: Using the wrong assembly file

I found the cause for the issue:
In PowerShell I am using the dll that is installed in the WinSCP folder. In C# I am using the netstandard dll from the nuget package.
Using the netstandard dll in PowerShell 7 resolves the issue.

Reply with quote

Advertisement

You can post new topics in this forum