2016-10-08 3 views
1

Ich habe versucht, die kompilierte Dll-Assembly von JSON.NET zu laden. Jedoch habe ich die folgende Fehlermeldung erhalten:Dll-Assembly kann nicht in Windows 10 geladen werden (Ausnahme von HRESULT: 0x80131515)

PS C:\Users\tamas\Desktop\garbage> Add-Type -path .\Newtonsoft.Json.dll 
Add-Type : Could not load file or assembly 'file:///C:\Users\tamas\Desktop\garbage\Newtonsoft.Json.dll' or one of its d 
ependencies. Operation is not supported. (Exception from HRESULT: 0x80131515) 
At line:1 char:1 
+ Add-Type -path .\Newtonsoft.Json.dll 
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
    + CategoryInfo   : NotSpecified: (:) [Add-Type], FileLoadException 
    + FullyQualifiedErrorId : System.IO.FileLoadException,Microsoft.PowerShell.Commands.AddTypeCommand 

auf einem anderen Computer unter Windows 7 konnte ich die gleiche Sache ohne Probleme tun. Was könnte die Ursache und die Lösung sein?

Meine .NET-Version:

PS C:\Users\tamas\Desktop\garbage> [System.Environment]::Version 

Major Minor Build Revision 
----- ----- ----- -------- 
4  0  30319 42000 

Powershell-Version:

PS C:\Users\tamas\Desktop\garbage> $Host.Version 

Major Minor Build Revision 
----- ----- ----- -------- 
5  1  14393 206 

Antwort

1

Dank @ martin-brandl ‚s suggeston ich in der Lage war, das Problem herauszufinden, (ich hatte tatsächlich seinen Code zu modifizieren, becuase es nicht ausgegeben haben etwas ($global:error[0].Exception hat keine Loaderexceptions Feld.))

PS C:\Users\tamas\Desktop\garbage> 
>> try 
>> { 
>>  Add-Type -Path .\Newtonsoft.Json.dll 
>> } 
>> catch 
>> { 
>>   write-host $global:error[0].Exception.InnerException 
>> } 
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused th 
e assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enabl 
e CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please ena 
ble the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569 for more information. 

Es stellte sich heraus, dass, da die dLL-Datei von einer externen Quelle war, aus Sicherheitsgründen Powershell eine Ausnahme ausgelöst. Mit th UnsafeLoadFrom(...) Methode konnte ich die dll Assembly laden:

PS C:\Users\tamas\Desktop\garbage> [System.Reflection.Assembly]::UnsafeLoadFrom("c:\users\tamas\Desktop\garbage\Newtonso 
ft.Json.dll") # absolute path required here!! 

GAC Version  Location 
--- -------  -------- 
False v4.0.30319  C:\Users\tamas\Desktop\garbage\Newtonsoft.Json.dll 

Mehr Informationen zu diesem Thema finden Sie here auf der MSDN-Website zu finden.

1

Ich kann Ihnen nicht sagen, welche die Abhängigkeiten Sie vermissen, aber ich kann Ihnen sagen, wie es zu erfahren. umgeben Ihr nur Add-Type innerhalb eines try-catch cand Abrufen der LoaderException:

try 
{ 
    Add-Type -Path .\Newtonsoft.Json.dll 
} 
catch 
{ 
     $global:error[0].Exception.LoaderExceptions | % { Write-Host $_ } 
} 
+0

danke! Ihre Antwort hat mir geholfen, die Lösung zu finden. Siehe meine Antwort auf die Frage. – ThomasMX

Verwandte Themen