Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

chen83193093

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.
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 netstandard dll from the nuget package.
Using the netstandard dll in PowerShell 7 resolves the issue.
pit5123

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

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.