无法执行的程序集加载到新的AppDomain,FileNotFoundException异常 [英] Unable to load executing assembly into new AppDomain, FileNotFoundException
问题描述
我想举办一个新的AppDomain中的文本模板类代理
I am trying to host a text template class proxy inside a new AppDomain.
我有一些旧的脚本代码,做类似的东西,包含此工作代码:
I have some old scripting code that does something similar, that contains this working code:
_ScriptAppDomain = AppDomain.CreateDomain(scriptDomainFriendlyName);
_ScriptProxy = (IScriptEngineProxy)_ScriptAppDomain.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName,
"LVK.Scripting.ScriptEngineProxy");
然而,当我尝试这与我的新类,有以下
However, when I try this with my new class, with the following
_TemplateDomain = AppDomain.CreateDomain(templateDomainFriendlyName);
_TemplateProxy = (ITemplateProxy)_TemplateDomain.CreateInstanceAndUnwrap(
Assembly.GetExecutingAssembly().FullName,
"TextTemplate.TemplateProxy");
我刚刚获得FileNotFoundException异常,具有以下细节:
I just get "FileNotFoundException", with the following details:
无法加载文件或程序集TextTemplate,版本= 1.0.0.0,文化=中性公钥= bb70a2e62a722ace'或它的一个依赖。该系统找不到指定的文件。
Could not load file or assembly 'TextTemplate, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb70a2e62a722ace' or one of its dependencies. The system cannot find the file specified.
我缺少什么?
基本上,我在TextTemplate命名空间(和装配),它试图加载TemplateProxy类(从MarshalByRefObject降序)进入新的AppDomain一个模板类,但它似乎我的主要组件没有加载到这个领域。
Basically, I have a Template class in the TextTemplate namespace (and assembly), which tries to load a TemplateProxy class (descending from MarshalByRefObject) into the new appdomain, but it appears my main assembly is not loaded into this domain.
这工作,如果我用的是旧的代码,但不能用这个新的,但我不能当场区别。
This works if I use the older code, but not with this new one, but I can't spot the difference.
下面是一些更多的细节:
Here's some more details:
- 大会未与GAC注册的(也不是旧人,其中工程)
- 我还没有覆盖的任何AssemblyResolve事件(也没有旧人,其中工程)
我不反对处理AssemblyResolve事件,如果是需要什么。我只是觉得奇怪的是,我的旧代码工作,这没有。
I'm not averse to handling the AssemblyResolve event, if that is what is needed. I just found it odd that my old code worked, and this didn't.
推荐答案
Assumying您的程序集是在同一目录作为当前应用程序的基础,可以尝试应用基地:
Assumying your assembly is in the same directory as your current application base, try specifying Application Base:
AppDomain.CreateDomain(templateDomainFriendlyName, null,
new AppDomainSetup
{
ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase
});
这篇关于无法执行的程序集加载到新的AppDomain,FileNotFoundException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!