Powershell data load error: Add-Type: Failed to load file or assembly "WebDriver.dll" or one of its dependencies. Operation not supported

I want to use PowerShell with selenium and download selenium from http://www.java2s.com/Code/Jar/s/Downloadseleniumremotedriver2350jar.htm . When I try to load one of the DLLs, I have errors. Hope someone can help me.

This is my system information.

 OS Name: Microsoft Windows 7 Enterprise OS Version: 6.1.7601 Service Pack 1 Build 7601 OS Manufacturer: Microsoft Corporation 

This is my PowerShell info.

 PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> $psversiontable Name Value ---- ----- PSVersion 4.0 WSManStackVersion 3.0 SerializationVersion 1.1.0.1 CLRVersion 4.0.30319.18052 BuildVersion 6.3.9421.0 PSCompatibleVersions {1.0, 2.0, 3.0, 4.0} PSRemotingProtocolVersion 2.2 PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> 

These are the errors that I received while trying to load the DLL.

  PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> Add-Type -Path .\WebDriver.dll Add-Type : Could not load file or assembly 'file:///C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) At line:1 char:1 + Add-Type -Path .\WebDriver.dll + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Add-Type], FileLoadException + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom(".\WebDriver.dll") Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\WebDriver.dll' or one of its dependencies. The system cannot find the file specified." At line:1 char:1 + [reflection.assembly]::LoadFrom(".\WebDriver.dll") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FileNotFoundException PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom("WebDriver.dll") Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\WebDriver.dll' or one of its dependencies. The system cannot find the file specified." At line:1 char:1 + [reflection.assembly]::LoadFrom("WebDriver.dll") + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FileNotFoundException PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFrom("C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll") Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)" At line:1 char:1 + [reflection.assembly]::LoadFrom("C:\Users\test\Downloads\selenium-dotnet-2.35.0 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : FileLoadException PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> [reflection.assembly]::LoadFile("C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40\WebDriver.dll") Exception calling "LoadFile" with "1" argument(s): "An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information." At line:1 char:1 + [reflection.assembly]::LoadFile("C:\Users\test\Downloads\selenium-dotnet-2.35.0 ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : NotSupportedException PS C:\Users\test\Downloads\selenium-dotnet-2.35.0\net40> 
+6
source share
2 answers

If you downloaded .LLL from the Internet, Powershell will not trust them by default. Here you can do one of two things:

  • Unlock content. Here is a guide with some details of the problem , but essentially you just need to right-click on the downloaded file, select β€œProperties” and click β€œUnlock 'on the general tab. You can unlock content directly from the command line using the Unblock-File cmdlet.
  • Change the execution policy . It also allows you to run malicious scripts that you download, so be careful.

In particular, viewing and unblocking content that you trust seems like the best route, especially for your case, as it seems that you only do it once and you trust this package.


Edit: If this could not be solved, another experience that I had with this type of error was that Powershell was not the same version of the .NET runtime as the assembly. See this question for some context where Powershell 2.0 ran the .NET 2 runtime, and some builders required .NET 4.

You do not use the same version of PS, so your mileage may vary, but I would try to create / edit a configuration file for the associated answer in order to maintain the runtime of the DLLs you are using.

+23
source

This worked for me: (from fooobar.com/questions/787369 / ... )

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> 
+2
source

Source: https://habr.com/ru/post/953822/


All Articles