从网络UNC共享错误0x80131515添加类型加载程序集

ALI*_*ake 5 powershell selenium add-type

如果要使用以下命令从网络UNC共享添加程序集:

$scriptPath = Split-Path ($MyInvocation.MyCommand.Path)
Add-Type -path "$scriptPath\selenium-dotnet\net40\WebDriver.dll"
Run Code Online (Sandbox Code Playgroud)

你可能会遇到这样的错误:

Add-Type: Could not load file or assembly 'file:///Z:\A-Backup\Users\Administr
ator\Desktop\MAXIMO Automatic\selenium-dotnet\net40\WebDriver.dll' or one of it
s dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)
At Z:\A-Backup\Users\Administrator\Desktop\MAXIMO Automatic\MAXIMO Automatic.ps
1:14 char:1
+ Add-Type -path "$scriptPath\selenium-dotnet\net40\WebDriver.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell
   .Commands.AddTypeCommand
Run Code Online (Sandbox Code Playgroud)

我该如何解决这个问题?

ALI*_*ake 10

关键是允许从PowerShell可执行文件的网络路径加载程序集.可以通过创建两个文件来完成

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>
Run Code Online (Sandbox Code Playgroud)

  • 看来你不能在 Windows Server 2012 R2 中执行此操作 - 访问被拒绝。 (2认同)