当前位置: 首页 > 面试题库 >

Powershell加载dll错误:Add-Type:无法加载文件或程序集“ WebDriver.dll”或其依赖项之一。不支持操作

南门朗
2023-03-14
问题内容

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

这是我的系统信息。

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

这是我的PowerShell信息。

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时遇到的错误。

    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>

问题答案:

如果从Internet下载.DLL,默认情况下Powershell将不信任它们。您可以在此处执行以下两项操作之一:

  1. 取消阻止内容。这是有关该问题的详细说明的指南,但实际上,您只需要右键单击下载的文件,选择“属性”,然后在常规选项卡中单击“取消阻止”。您可以使用Unblock-Filecmdlet 直接从powershell取消阻止内容。
  2. 更改执行策略。这也可能允许您下载的恶意脚本运行,因此要小心。

专门查看和取消阻止您信任的内容似乎是更好的方法,特别是对于您的情况,因为您似乎只需要执行一次并且信任该程序包。

编辑:
如果那不能解决问题,那么我对这种类型的错误的另一种体验是当Powershell与程序集没有.NET运行时版本时。
2.0运行.NET 2运行时,而问询者需要某些组件的.NET 4。

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



 类似资料:
  • 我在我的网站(web应用程序)中使用了Umbraco 4.11.6。我的网站在localhost上运行(在Visual studio 2012和IIS(v7)上测试过),但是当我在互联网上运行时,出现了一个错误。错误是: 程序集加载跟踪:以下信息有助于确定程序集“System.Web”的原因。无法加载“剃刀”。 WRN:程序集绑定日志记录已关闭。若要启用程序集绑定失败日志记录,请设置注册表值 [H

  • 我尝试将两个 ASP.NET Web 项目(一个 Facebook 应用程序和一个机器人)部署到同一个 Azure 网站,但在我部署了它们之后,我收到了: 无法加载文件或程序集“System.Web”。Mvc’或其依赖项之一。找到的程序集的清单定义与程序集引用不匹配。(HRESULT异常:0x80131040) 我不确定我能做什么,除了从头开始并将两个项目合并成一个项目(不可取)重新发布。到目前为

  • 我在我的应用程序中使用MVC 5,WCF和Unity框架。 当我运行WCF服务时,我收到以下错误: 我已添加System.Web.WebPages。WCF项目中的Razor,版本=3.0.0.0,仍然存在相同的错误。 有人知道如何解决这个错误吗?

  • 问题内容: 我正在使用sharepoint2010。我创建了一个简单的可视化Web部件,其中包含一个文本框,并向其中添加了calendarextender。我已添加为参考。但是,当我部署到SharePoint网站时,它给了我以下错误。 “解析器错误”消息: 无法加载文件或程序集“ AjaxControlToolkit”或其依赖项之一。该系统找不到指定的文件。 源错误: 第3行:<%@ Regist

  • 问题内容: 搜索后我尝试过的事情: 在Web.Config中,对旧版本进行绑定: 问题答案: 好的,我想我现在可以开始工作了。我删除了机器上所有不是我可以找到的最新版本的Newtonsoft.Json.dll,确保在NuGet中拥有最新版本,并进行构建,并确保它是bin文件夹中的最新版本,并且我将更改保留在web.config和.csproj中。现在,我遇到另一个错误,因此它必须正在工作。

  • 我有一个图书馆AXInterop。WMPLib,它快把我逼疯了。这是我收到的错误。我没有使用任何其他依赖项。 堆栈跟踪: [文件加载异常:无法加载文件或程序集'AxInterop.WMPLib'或其依赖项之一。参数不正确。(HRESULT异常:0x80070057(E_INVALIDARG))] [FileLoadException:无法加载文件或程序集“AxInterop.WMPLib,Vers