我将一个函数加载到新创建的AppDomain中,所有工作都正常,但如果我关闭程序,然后将其重命名并再次启动它,那么我将遇到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");
}
}
}
DoCallBack
出现错误。有趣的是,一个看起来和这个问题重复的Q被从SO中删除了:http://stackoverflow.com/questions/30512932/execute-code-in-appdomain-in-renamed-executables - Cee McSharpface