PowerShell runtime exception - "could not load file or assembly"

Mark Jenster picture Mark Jenster · Dec 10, 2012 · Viewed 42.7k times · Source

This seems to be a common problem in PowerShell and Visual Studio, yet cases and solutions seem to vary a lot. Though seeing several similar questions, I didn't find a working solution for my issue yet.

The problem exists in the error message

Could not load file or assembly 'file:///C:\users\jenstmar\Desktop\WinSCP.dll' o r one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

The file location is invalid, as the .dll is supposed to be located in the same folder as the WinSCP installation. This location was changed to check that no rights or lack thereof, restricted me to use it.

The script line that causes the problem looks as following:

# Load WinSCP .NET assembly
[Reflection.Assembly]::LoadFrom("C:\users\jenstmar\Desktop\WinSCP.dll") | Out-Null

This error comes in both PowerShell ISE and PS ISE(x86). I run PowerShell V3.0 in a Windows Enterprise 64 bit environment as local administrator. How can I fix this problem?

Answer

Chris N picture Chris N · Dec 10, 2012

The file may be blocked from being loaded because of its origin (stored in NTFS streams). Check properties and see if the little unblock button is lit up. Once you unblock it perhaps it will load...