Session.Open() fails in PowerShell 7.0.0-preview.5 with Method not found: EventWaitHandle

Advertisement

pit5123
Joined:
Posts:
2
Location:
Germany

Session.Open() fails in PowerShell 7.0.0-preview.5 with Method not found: EventWaitHandle

Using WinSCP 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. But 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

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 .NET Standard dll from the NuGet package (netstandard2.0).
Using the .NET Standard dll in PowerShell 7 resolves the issue.

Reply with quote

chen83193093
Joined:
Posts:
1
Location:
Beijing

Resolved: Set a specified ExecutablePath

Add-Type -Path "D:\Tools\WinSCP\netstandard2.0\WinSCPnet.dll" #Set WinSCP.net dll location
 
$session = New-Object WinSCP.Session
$session.ExecutablePath="D:\Tools\WinSCP\WinSCP.exe" # Set WinSCP.exe path and the error gone   
$session.DebugLogPath="D:\xxx.log"  #If errors occurred, look into the log file.

Reply with quote E-mail

Advertisement

You can post new topics in this forum