【问题标题】:assemblies not resolving while creating instance from AppDomain从 AppDomain 创建实例时程序集未解析
【发布时间】:2012-04-05 08:08:56
【问题描述】:
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/>

我仍然在应用程序域中寻找自己的方式。
我做错了什么?

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

【问题讨论】:

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


    【解决方案1】:

    我的猜测是,不是未找到该程序集,而是未正确加载引用的程序集之一。您可能需要处理父应用程序域中的解析程序集事件。这里有一篇很好的文章来描述它。

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

    【讨论】:

    • 您还可以处理ReflectionTypeLoadException 并查看LoaderExceptions 属性以确定是否无法解析任何引用的程序集。比处理事件恕我直言更容易。
    猜你喜欢
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 2015-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多