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 "$scriptPath\selenium-dotnet\net40\WebDriver.dll"

you might face such an error:

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
1:14 char:1
+ Add-Type -path "$scriptPath\selenium-dotnet\net40\WebDriver.dll"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Add-Type], FileLoadException
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell

How can I fix this problem?

asked on Stack Overflow Nov 13, 2013 by ALIENQuake • edited Jul 14, 2015 by Peter Mortensen

3 Answers


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:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe.config C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe.config

and paste this code:

<?xml version="1.0" encoding="utf-8" ?> 
      <loadFromRemoteSources enabled="true"/>
answered on Stack Overflow Nov 13, 2013 by ALIENQuake • edited Jul 14, 2015 by Peter Mortensen

Re: ALIENQuake's. I've added your fix to a PS script to install the files in the correct locations.

$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" ?> 
         <loadFromRemoteSources enabled="true"/>
foreach($PSConfigFile in $PSPaths) {
    $xmlcode | Out-File -FilePath $PSConfigFile -Encoding utf8 
answered on Stack Overflow Jan 16, 2015 by Josh Castillo • edited Sep 17, 2015 by Emond Erno

Instead of Add-Type you could:


It'll ignore some security settings and load the library but it's, well, unsafe ;).

answered on Stack Overflow Jun 30, 2017 by AdamL

User contributions licensed under CC BY-SA 3.0