PowerShell workspace exception - “cannot load file or assembly”

This seems to be a common problem in PowerShell and Visual Studio, but the cases and solutions seem to be very different. Although I saw several similar questions, I have not yet found a working solution to my problem.

The problem occurs in the error message.

Failed to load file or assembly 'file: /// C: \ users \ jenstmar \ Desktop \ WinSCP.dll' One of its dependencies. The operation is not supported. (Exception from HRESULT: 0x80131515)

The file location is not valid because it is assumed that the .dll is in the same folder as the WinSCP installation. This place was changed to check if there were any rights or deficiencies that limited me to how to use it.

The line of script causing the problem is as follows:

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

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

+10
source share
6 answers

The solution in this case: Remove and download it all again. I even unlocked it in the first file, without help. Glad it was on the inside machine.

+7
source

A file may be locked due to its origin (stored in NTFS streams ). Check the properties and see if the small unlock button is lit. As soon as you unlock it, maybe it will boot ...

+11
source

The following worked for me (from the issue of stack overflow, Add-Type boot assembly from UNC network error 0x80131515 ).

In the files:

C: \ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe.config C: \ Windows \ SysWOW64 \ WindowsPowerShell \ v1.0 \ powershell.exe.config

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <loadFromRemoteSources enabled="true"/> </runtime> </configuration> 
+3
source
 Import-Module : Could not load file or assembly 'file:/// *dll path*' or one of its dependencies. An attempt was made to load a program with an incorrect format. At *script path*.ps1:68 char:2 + Import-Module *module path* + ~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Import-Module], BadImageFormatException + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand 

If you see the above error, there may be a problem starting Windows PowerShell ISE in 32-bit mode (Windows PowerShell ISE (x86)). You need to run the Windows PowerShell ISE application.

This application (Windows PowerShell ISE) is in 64 bit mode. When I ran the power shell command, it works great for me.

I tried to fix this with different types of solutions, but this did not work for me. If you use 32 mode, switch it to 64 bit and try.

+1
source

I would look at WinSCP.dll dependencies in ILDASM or dotPeek, and then load these dependencies before loading WinSCP.dll. The problem is that you are working in the context of loading PowerShell.exe (or powershell_ise.exe), and assemblies that WinSCP.dll will not be found in these two exe base directories. Therefore, you will need to load dependent assemblies before the CLR loader slams because it cannot find the required DLL. If you need help finding out which assembly is not found, check out the fuslogvw.exe tool.

By the way, with PowerShell v2 you should use Add-Type -Path <path> instead of [SRA] :: LoadFrom (...).

0
source

There was the same problem and it worked for me:

Right-click on the DLL file. ( WinSCP.dll in your case)
Below, on the "General" tab, there may be an unlock option. Check this option to unlock the file.

0
source

All Articles