Powershell加载dll得到错误:添加类型:无法加载文件或程序集“WebDriver.dll”或其依赖关系之一。不支持操作 [英] Powershell load dll got error: Add-Type : Could not load file or assembly 'WebDriver.dll' or one of its dependencies. Operation is not supported

查看:965
本文介绍了Powershell加载dll得到错误:添加类型:无法加载文件或程序集“WebDriver.dll”或其依赖关系之一。不支持操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 PowerShell selenium 并从 http://www.java2s.com/Code/Jar/s/Downloadseleniumremotedriver2350jar.htm 。当我尝试加载其中一个DLL时,我收到错误。希望有人可以帮助我。

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 got errors. Hope someone can help me with it.

这是我的系统信息。

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

这是我的PowerShell信息。

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>

这是我在尝试加载dll时遇到的错误。

This is the errors I got when 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>


推荐答案

如果你从互联网上下载了.DLLs,Powershell默认不会信任他们,你可以在这里做两件事:

If you downloaded the .DLLs from the internet, Powershell by default will not trust them. You can do one of two things here:


  1. 取消屏蔽内容,这是一个有关问题的一些细节的指导,但本质上你只需右键单击下载的文件,选择属性,然后在常规选项卡中单击解除阻止。您可以使用 Unblock-File cmdlet直接从powershell中解除封锁。

  2. 更改您的执行政策。这也可以允许您下载的恶意脚本运行,因此要谨慎。

  1. Unblock the content. Here's a guide with some elaboration on the problem, but essentially you just need to right-click on the downloaded file, select Properties, and click 'Unblock' in the general tab. You can unblock content directly from powershell by using the Unblock-File cmdlet.
  2. Change your execution policy. This can also allow malicious scripts that you download to run, so be cautious.

具体查看和解除封锁您信任的内容似乎更好的路由,特别是对于你的情况,因为你似乎只会这样做一次,你信任的包。

Specifically reviewing and unblocking content you trust seems the better route, especially for your case since you seem like you would only be doing this once and you trust the package.

编辑:如果没有解决这个问题,我遇到这种类型的错误的另一个经验是Powershell与程序集不同的.NET运行时版本。对于某些上下文,请参阅此问题,其中Powershell 2.0运行.NET 2运行时,asker需要.NET 4用于某些程序集。

If that didn't solve that, the other experience I've had with this type of error is when Powershell didn't 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 the asker needed .NET 4 for some assemblies.

您没有使用相同版本的PS,因此您的里程可能会有所不同,但我会尝试创建/编辑每个链接的答案的配置文件,以支持您正在使用的DLL。

You're not using the same version of PS so your mileage may vary, but I would try creating/editing a config file per the linked answer to support the runtime of the DLLs you are using.

这篇关于Powershell加载dll得到错误:添加类型:无法加载文件或程序集“WebDriver.dll”或其依赖关系之一。不支持操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆