2
votes

I'm trying to load WinSCPnet.dll file using below code in PowerShell, and I'm getting below error.

Set-Location "D:\WinSCP-5.17.10-Automation"
Add-Type -Path "WinSCPnet.dll"

Add-Type : Could not load file or assembly 'file:///D:\WinSCP-5.17.10-Automatio n\WinSCPnet.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
At line:2 char:9
+ Add-Type <<<< -Path "WinSCPnet.dll"
+ CategoryInfo : NotSpecified: (:) [Add-Type], BadImageFormatExce ption
+ FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerSh ell.Commands.AddTypeCommand

Is there any other way to add this assembly in PowerShell 2.0 and if it is not supported is there any WinSCPnet.dll available, which supports PowerShell 2.0?

1

1 Answers

1
votes

I do not think the problem is about PowerShell 2 as such. It's about the .NET framework version loaded by PowerShell. The current version of WinSCP .NET assembly targets .NET 4.0. You likely have that version installed. You just need to configure PowerShell to use it.

There's WinSCP article that covers this:
https://winscp.net/eng/docs/message_net_runtime_newer_than_currently_loaded

As suggested there, try:

set COMPLUS_version=v4.0.30319
powershell ...