2013-07-26 2 views
2

별도의 AppDomain에서 실행할 클래스를 호출하려고하지만 클래스 또는 해당 종속 항목 중 하나를로드 할 수 없다는 점에 대해 예외가 발생합니다. 내가하는 일의 예가 여기있다.AppDomain에서 클래스의 새 인스턴스를 만드는 방법

내 별도의 TestProject에서
AppDomain ad = AppDomain.CreateDomain("New domain"); 
IIdentity identity = new GenericIdentity("NewUser"); 
IPrincipal principal = new GenericPrincipal(identity, null); 
ad.SetThreadPrincipal(principal); 
TestClass remoteWorker = (TestClass)ad.CreateInstanceAndUnwrap(
         binFolder+"\\TestProject.dll", 
         "TestClass"); 
remoteWorker.Run(data1,data2); 

나는 하나 개의 클래스라는 이름의 TestClass이 : 나는 모든 것을 모든 경로를 확인했습니다

public class TestClass : MarshalByRefObject 
{ 
     public void Run(string name, string path) 
     { 
      //Some stuff 
     } 
    } 

을 그들이 정확합니다. 오류가 나타납니다.

Could not load file or assembly 'K:\\Installer\\Bin\\TestProject.dll' 
or one of its dependencies. The given assembly name or codebase was invalid. 
(Exception from HRESULT: 0x80131047) 

경로를 변경하여 현재 실행중인 어셈블리로 옮겨 보았습니다. 아직 아무것도. DLL은 K : \ Installer \ Bin \ TestProject.dll에 있습니다. 나는 Dll에 대한 권한을 가지기 위해 이것을 admin 아래에서 실행하고있다.

+0

'ReflectionTypeLoadException' 예외를 잡으려고 했습니까? "TestProject.dll"에 런타임이 해결할 수없는 일부 종속성이있을 수 있습니다. – McGarnagle

+0

포함하는 유일한 것은 시스템 DLL입니다. 그 사람들은 어떻게 해결되지 않을까요? – busbina

답변

1

알아 냈어. 내 코드를 다음으로 변경했습니다 :

AppDomainSetup domainSetup = new AppDomainSetup 
          {PrivateBinPath = binFolder+"\\TestProject.dll"}; 
AppDomain ad = AppDomain.CreateDomain("New domain",null, domainSetup); 

TestClass remoteWorker = (TestClass)ad.CreateInstanceFromAndUnwrap(
          binFolder+"\\TestProject.dll", 
          typeof(TestClass).FullName); 
관련 문제