2016-10-08 2 views
1

JSON.NET의 컴파일 된 dll 어셈블리를로드하려고했습니다. 그러나 다음과 같은 오류 메시지가 나타납니다.Windows 10에서 dll 어셈블리를로드 할 수 없습니다 (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 

다른 컴퓨터에서 Windows 7에서 아무런 문제없이 똑같은 작업을 수행 할 수있었습니다. 원인과 해결책은 무엇이 될 수 있습니까?

내 .NET 버전 :

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

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

PowerShell을 버전 :

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

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

답변

1

감사가 출력되지 않았다 becuase (사실, 자신의 코드를 수정했다 아무것도 ($global:error[0].Exception은 LoaderExceptions 필드가 없습니다.))

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. 

이 DLL 파일은 외부 소스에서 이었기 때문에, 안전상의 이유로 powershell을 위해 예외를 던진 것으로 밝혀졌다. 이 문제에 대한

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 

더 많은 정보는 MSDN 사이트 here에서 찾을 수 있습니다 : UnsafeLoadFrom(...) 방법 번째 사용 나는 DLL 어셈블리를로드 할 수 있었다.

1

나는 종속성 누락하는 당신에게 말할 수 있지만 내가 어떻게 알아 방법을 알 수 있습니다. 그냥 try-catchAdd-TypeLoaderException 검색 모시의 서라운드 : 나는 문제를 알아낼 수 있었다 @ 마틴 - 브랜의 suggeston에

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

감사합니다. 당신의 대답이 나를 해결책으로 이끌어주었습니다. 질문에 대한 내 대답을보십시오. – ThomasMX

관련 문제