Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

powershell - Add-Type load assembly from network UNC share error 0x80131515

When you want to add an assembly from a network UNC share using the command:

$scriptPath = Split-Path ($MyInvocation.MyCommand.Path)
Add-Type -path "$scriptPathselenium-dotnet
et40WebDriver.dll"

you might face such an error:

Add-Type: Could not load file or assembly 'file:///Z:A-BackupUsersAdministr
atorDesktopMAXIMO Automaticselenium-dotnet
et40WebDriver.dll' or one of it
s dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515
)
At Z:A-BackupUsersAdministratorDesktopMAXIMO AutomaticMAXIMO Automatic.ps
1:14 char:1
+ Add-Type -path "$scriptPathselenium-dotnet
et40WebDriver.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell
   .Commands.AddTypeCommand

How can I fix this problem?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The key is to allow for loading an assembly from a network path for a PowerShell executable. It can be done by creating the two files

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe.config C:WindowsSysWOW64WindowsPowerShellv1.0powershell.exe.config

and paste this code:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...