6

次のコマンドを使用して、ネットワークUNC共有からアセンブリを追加する場合:

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

次のようなエラーが発生する可能性があります。

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

この問題を解決するにはどうすればよいですか?

4

3 に答える 3

10

重要なのは、PowerShell 実行可能ファイルのネットワーク パスからアセンブリをロードできるようにすることです。2つのファイルを作成することで実行できます

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>
于 2013-11-13T15:05:37.483 に答える
4

Re:ALIENQuakeさん。ファイルを正しい場所にインストールするために、修正を PS スクリプトに追加しました。

$PSPaths = 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config','C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config'
$XMLCode = @"
<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
   <runtime>
         <loadFromRemoteSources enabled="true"/>
    </runtime>
</configuration>
"@
foreach($PSConfigFile in $PSPaths) {
    $xmlcode | Out-File -FilePath $PSConfigFile -Encoding utf8 
}
于 2015-01-16T19:51:50.593 に答える