我加載一個函數到新創建的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