无法将执行程序集加载到新的 AppDomain 中,FileNotFoundException [英] Unable to load executing assembly into new AppDomain, FileNotFoundException

查看:53
本文介绍了无法将执行程序集加载到新的 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, Version=1.0.0.0, Culture=neutral, PublicKeyToken=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 命名空间(和程序集)中有一个 Template 类,它尝试将 TemplateProxy 类(从 MarshalByRefObject 降序)加载到新的应用程序域中,但似乎我的主程序集未加载到该域中.

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.

以下是更多详细信息:

  • Assembly 未在 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 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆