我加载一个函数到新创建的AppDomain并且所有的工作都很好,但是如果我关闭程序然后重新命名并重新启动它,那么我会有FileNotFound异常。我只是不明白,那怎么可能?AppDomain DoCallBack FileNotFound异常
错误(appDomainProject原来的程序名)
System.IO.FileNotFoundException: Could not load file or assembly "appDomainProject, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = null" or one of its dependencies. Can not find the file specified.
来源
using System;
using System.IO;
using System.Windows.Forms;
namespace appDomainProject
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
AppDomain authDomain = AppDomain.CreateDomain(DateTime.Now.ToString());
authDomain.DoCallBack(load_Auth);
}
catch (Exception ex)
{
File.WriteAllText("e.txt", ex.ToString());;
MessageBox.Show(ex.ToString());
}
}
private static void load_Auth()
{
MessageBox.Show("AUTH");
}
}
}
只是可以肯定的:“关闭程序并重新命名“,你的意思是你正在重命名exe文件,不涉及重建,没有在GAC或NGen等中注册? – dlatikay
yeap,只需重新命名而不需重建 – SLI
即可重现。源代码行21,DoCallBack失败。有趣的是,看起来像这样的一个重复的Q,被删除从SO:http://stackoverflow.com/questions/30512932/execute-code-in-appdomain-in-renamed-executables – dlatikay