Reputation: 317
Error Message:
Add-Type : Could not load file or assembly 'file:///D:\WinSCP-5.15.2-Automation\WinSCPnet.dll' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded. I placed WinSCP.dll same folder together with WinSCP.exe**
I run PowerShell v2.0.
The problem exists in the error message
The script line that causes the problem looks as following:
#Load WinSCP .NET assembly
Add-Type -Path "C:\users\Desktop\WinSCPnet.dll"
This post almost similar with this link PowerShell runtime exception - "could not load file or assembly" and I tried every method posted in the link and unable to solve it. Is there anything I missed out?
Upvotes: 1
Views: 3622
Reputation: 202652
You probably have an old version of .NET Framework.
Recent versions of WinSCP .NET assembly target .NET Framework 4.0.
WinSCP 5.13.9 was the last version that worked in .NET 2.
You should use the latest version of WinSCP and .NET though. Both are security sensitive software after all.
If you cannot install .NET Framework 4 (not recommended though), you can use WinSCP scripting instead of .NET assembly. WinSCP itself does not have any dependency on .NET Framework (or anything else). And runs on all versions of Windows since Windows XP.
Upvotes: 1