2016-09-02 4 views
1

리플렉션을 사용하여 두 개의 어셈블리를로드하고 그 중 몇 가지 유형을 사용하고 있습니다. 어셈블리를로드하고 형식을로드 한 다음 Activator를 사용하여 형식을 인스턴스화하면 "LoadFromXml"메서드를 호출 할 때 어셈블리에서 FileNotFound 예외가 발생합니다. 이것은 이전에 작동했는데 무엇이 바뀌 었는지 알 수 없습니다. 또한 문제없이 만든 인스턴스에서 속성을 가져올 수 있습니다. "LoadFromXml"메서드를 호출 할 때만 예외가 발생합니다.어셈블리를 성공적으로로드 한 후 파일을 찾을 수 없습니다.

private static object CheckForVersion(int version, string constructFilePath, string utilityFilePath) 
    { 
     if (!System.IO.File.Exists(constructFilePath) || !System.IO.File.Exists(utilityFilePath) || version < 7) return null; 

     var utilAssembly = System.Reflection.Assembly.LoadFile(utilityFilePath); 
     var constructAssembly = System.Reflection.Assembly.LoadFile(constructFilePath); 

     var InfoManager = utilAssembly.GetType(String.Format("{0}.InfoManager", utilAssembly.FullName.Split(',')[0])); 
     var ExecutionServerPropertiesConstructType = constructAssembly.GetType(String.Format("{0}.ExecutionServerPropertiesConstruct", constructAssembly.FullName.Split(',')[0])); 

     string dbFolder = (string)(InfoManager.GetProperty("ServerDatabaseFolder").GetValue(null, null)); 

     if (Directory.Exists(dbFolder) == true) 
     { 
      string FilePath = Path.Combine(dbFolder, @"ExecutionServer.config.xml");     //DONT LOCALIZE 

      dynamic theServerProperties = Activator.CreateInstance(ExecutionServerPropertiesConstructType); 

      theServerProperties.LoadFromXml(FilePath); 

      var retVal = new 
      { 
       InstalledProductVersion = version, 
       ServerGuid = (string)InfoManager.GetField("SERVER_GUID").GetValue(null), 
       WorkflowRootnodeGuid = (string)InfoManager.GetField("WORKFLOW_ROOTNODE_GUID").GetValue(null), 
       TaskRootnodeGuid = (string)InfoManager.GetField("TASK_ROOTNODE_GUID").GetValue(null), 
       TriggerRootnodeGuid = (string)InfoManager.GetField("TRIGGER_ROOTNODE_GUID").GetValue(null), 
       ProcessRootnodeGuid = (string)InfoManager.GetField("PROCESS_ROOTNODE_GUID").GetValue(null), 
       ConnectionString = theServerProperties.ConnectionString 
      }; 

      return Newtonsoft.Json.JsonConvert.SerializeObject(retVal); 
     } 

     return null; 
    } 

답변

1

좀 더 조사한 후에 파일이 다른 프로세스/어셈블리에서 이미로드 된 것처럼 보입니다. Reflection.LoadFile()에서 Reflection.LoadFrom()으로 변경하면 문제가 해결됩니다.