AppDomain DoCallBack FileNotFoundException-C# [英] AppDomain DoCallBack FileNotFoundException - C#

查看:148
本文介绍了AppDomain DoCallBack FileNotFoundException-C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下代码的C#2.0类:

I have a C# 2.0 class with the following code:

public class MyClass : MarshalByRefObject, IDisposable 
    {
        private string _appName;
        private AppDomain _app;

        public MyClass(string appName)
        {
            _appName = appName;
            _app = AppDomain.CreateDomain("NewDomain" + _appName);
            _app.DoCallBack(new CrossAppDomainDelegate(CallBackMethod));
        }

        public void Dispose()
        {
            AppDomain.Unload(_app);
        }

        public static void CallBackMethod()
        {
            //some operations
        }
    }

该类包含在类库项目下,然后从Web应用程序项目中引用.

This class is contained under a Class Library Project, then referenced from a Web Application Project.

因此,在我的网页中,我只是实例化该对象,期望该类的构造函数将创建该新AppDomain并执行指定的操作:

So, in my web page I just instance the object, expecting that the constructor of the class would create that new AppDomain and perform the specified operations:

MyClass objMyClass = new MyClass("12022012213456");

但我一直收到此错误:

无法加载文件或程序集'MyNamespace.MyClass,版本= 1.0.0.0,文化=中性,PublicKeyToken =空'或其依赖项之一.该系统找不到指定的文件.

Could not load file or assembly 'MyNamespace.MyClass, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

但是,奇怪的是,此异常发生在这一行:

But the curious thing here is that this exception is happening at this line:

_app.DoCallBack(new CrossAppDomainDelegate(CallBackMethod));

并且您可以看到,它发生在 MyClass 上,所以我不明白如何告诉我如果代码已经在执行中则找不到程序集???我就是不明白.

And as you can see, it's happening on MyClass, so I don't understand how could it tell me that the assembly could not be found if the code is already being executed??? I just don't get it.

顺便说一句,我是AppDomain的新手,也许我对某些概念感到困惑.

BTW, I'm a newbie at the usage of AppDomain, maybe I'm confused with some concept.

推荐答案

您创建的AppDomain(_app)似乎在查找程序集中的MyClass类时遇到问题.您的 CreateDomain 没有提供任何

It appears that the AppDomain you created (_app) is having problems locating your MyClass class in it's assembly. Your CreateDomain has not provided any AppDomainSetup information so it has no context for the current app domains directories nor assemblies. You have two options, provide a propertly configured AppDomainSetup or call _app.Load(Assembly.GetExecutingAssembly.FullName) prior to your DoCallBack method.

这篇关于AppDomain DoCallBack FileNotFoundException-C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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