从AppDomain创建实例时,程序集无法解析

时间:2012-04-05 08:08:56

标签: c# .net .net-4.0 assemblies appdomain

var processAssembly  = Assembly.LoadFile(baseLocationCCDebugFolder+"\\CC.dll");
var processType = processAssembly.GetType("CC.Executor.CCProcess",true,true);

AppDomainSetup appDSetup = new AppDomainSetup()
{
  ApplicationBase = baseLocationCCDebugFolder,
  //PrivateBinPath = processAssembly.CodeBase
};

StrongName fullTrustAssembly = processAssembly.Evidence.GetHostEvidence<StrongName>();

AppDomain executionDomain = AppDomain.CreateDomain("ExecutionDomain",null,appDSetup,internetPS,fullTrustAssembly);
CCProcess process =(CCProcess)executionDomain.CreateInstanceAndUnwrap(processAssembly.ManifestModule.FullyQualifiedName, processType.FullName);

我在这段代码的最后一行遇到错误。就像这样。

Could not load file or assembly 'D:\\work\\compilerCom\\CompileCom_Build_4_newArchitecture\\CompilerCom\\CC\\bin\\Debug\\CC.dll' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)<br/>

我仍然在app域中找到自己的方式。
我做错了什么?

编辑: - baseLocationCCDebugFolder变量的值为D:\\work\\compilerCom\\CompileCom_Build_4_newArchitecture\\CompilerCom\\CC\\bin\\Debug

1 个答案:

答案 0 :(得分:0)

我的猜测是,找不到程序集,但是其中一个引用的程序集未正确加载。您可能需要在父appdomain中处理resolve assembly事件。这里有一篇很好的帖子描述它。

http://social.msdn.microsoft.com/forums/en-US/clr/thread/0a18ed66-6995-4e7c-baab-61c1e528fb82/