Loading WinSCP in PowerShell - Could not load file or assembly - This assembly is built by a runtime newer than the currently loaded runtime

泪湿孤枕 提交于 2020-01-13 06:38:07

问题


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?


回答1:


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 though. It's a security software after all. If you cannot install .NET Framework 4, 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.



来源:https://stackoverflow.com/questions/57111027/loading-winscp-in-powershell-could-not-load-file-or-assembly-this-assembly-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!