source

Powershell load dll에 오류가 발생했습니다. Add-Type : 파일이나 어셈블리 'WebDriver.dll' 또는 해당 종속성 중 하나를 로드할 수 없습니다.작업이 지원되지 않습니다.

ittop 2023. 8. 25. 23:58
반응형

Powershell load dll에 오류가 발생했습니다. Add-Type : 파일이나 어셈블리 'WebDriver.dll' 또는 해당 종속성 중 하나를 로드할 수 없습니다.작업이 지원되지 않습니다.

사용하고 싶습니다.PowerShell와 함께seleniumhttp://www.java2s.com/Code/Jar/s/Downloadseleniumremotedriver2350jar.htm 에서 셀레늄을 다운로드합니다. 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>

를 다운로드한 경우.Powershell은 기본적으로 인터넷의 DLL을 신뢰하지 않습니다.여기서는 다음 두 가지 작업 중 하나를 수행할 수 있습니다.

  1. 콘텐츠 차단을 해제합니다.문제에 대해 자세히 설명한 가이드가 있지만 기본적으로 다운로드한 파일을 마우스 오른쪽 단추로 클릭하고 속성을 선택한 다음 일반 탭에서 '차단 해제'를 클릭하면 됩니다.다음을 사용하여 파워셸에서 직접 콘텐츠 차단을 해제할 수 있습니다.Unblock-Filecmdlet.
  2. 실행 정책을 변경합니다.이렇게 하면 다운로드한 악성 스크립트가 실행될 수도 있으므로 주의해야 합니다.

신뢰할 수 있는 콘텐츠를 구체적으로 검토하고 차단을 해제하는 것이 더 나은 방법인 것 같습니다. 특히 이 작업은 한 번만 수행하고 패키지를 신뢰하는 것처럼 보이기 때문입니다.


편집: 이 오류를 해결하지 못했다면 Powershell이 동일한 버전의 제품을 사용하지 않았을 때에도 이러한 오류를 경험되었습니다.NET 런타임을 어셈블리로 지정합니다.Powershell 2.0에서 를 실행한 일부 컨텍스트는 이 질문을 참조하십시오.NET 2 런타임과 질문자가 필요했습니다.일부 어셈블리의 경우 NET 4.

당신은 같은 버전의 PS를 사용하지 않기 때문에 마일리지가 다를 수 있지만, 저는 당신이 사용하고 있는 DLL의 런타임을 지원하기 위해 링크된 답변에 따라 구성 파일을 생성/편집하려고 합니다.

이것은 저에게 효과가 있었습니다. (https://stackoverflow.com/a/19957173/107161) 에서)

파일:

C:\Windows\시스템32\Windows PowerShell\v1.0\powershell.exe.config C:\Windows\SysWOW64\Windows PowerShell\v1.0\powershell.exe.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
   <runtime>
      <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

관리자 권한으로 실행이 문제를 해결했지만 내 Get-Execution 정책은 모두 서명되었습니다.

제가 한 일은

  1. 파일을 마우스 오른쪽 단추로 클릭하고 속성을 클릭하여 .dll 잠금 해제를 선택합니다.
  2. PS를 닫았다가 다시 엽니다.
  3. .ps1 스크립트 실행

언급URL : https://stackoverflow.com/questions/18801440/powershell-load-dll-got-error-add-type-could-not-load-file-or-assembly-webdr

반응형