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

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

问题描述

我想使用 PowerShellselenium 并从 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	estDownloadsselenium-dotnet-2.35.0
et40> $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	estDownloadsselenium-dotnet-2.35.0
et40>

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

This is the errors I got when trying to load the dll.

    PS C:Users	estDownloadsselenium-dotnet-2.35.0
et40> Add-Type -Path .WebDriver.dll
    Add-Type : Could not load file or assembly 'file:///C:Users	estDownloadsselenium-dotnet-2.35.0
et40WebDriver.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	estDownloadsselenium-dotnet-2.35.0
et40> [reflection.assembly]::LoadFrom(".WebDriver.dll")
    Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:Users	estWebDriver.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	estDownloadsselenium-dotnet-2.35.0
et40> [reflection.assembly]::LoadFrom("WebDriver.dll")
    Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:Users	estWebDriver.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	estDownloadsselenium-dotnet-2.35.0
et40> [reflection.assembly]::LoadFrom("C:Users	estDownloadsselenium-dotnet-2.35.0
et40WebDriver.dll")
    Exception calling "LoadFrom" with "1" argument(s): "Could not load file or assembly 'file:///C:Users	estDownloadsselenium-dotnet-2.35.0
et40WebDriver.dll' or
    one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
    At line:1 char:1
    + [reflection.assembly]::LoadFrom("C:Users	estDownloadsselenium-dotnet-2.35.0 ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : FileLoadException

    PS C:Users	estDownloadsselenium-dotnet-2.35.0
et40> [reflection.assembly]::LoadFile("C:Users	estDownloadsselenium-dotnet-2.35.0
et40WebDriver.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	estDownloadsselenium-dotnet-2.35.0 ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : NotSupportedException

    PS C:Users	estDownloadsselenium-dotnet-2.35.0
et40>

推荐答案

如果您从 Internet 下载了 .DLL,默认情况下 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 运行时,并且请求者需要 .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天全站免登陆