最简单的AppDomain和FileNotFound异常

时间:2013-05-24 09:15:34

标签: c# .net appdomain

我写了一个简单的创建单独的AppDomain的行,但是得到FileNotFound的奇怪异常:无法加载文件或程序集......考虑到必要的参数被填充,这个问题让我非常困惑:

AppDomainSetup setup = new AppDomainSetup();
setup.ApplicationBase = Assembly.GetExecutingAssembly().CodeBase;
Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);
evidence.AddAssembly(Assembly.GetExecutingAssembly().FullName);
evidence.AddHost(new Zone(SecurityZone.MyComputer));
AppDomain hostedAppDomain = AppDomain.CreateDomain("Demo", evidence, setup);                   
hostedAppDomain.AssemblyResolve += new ResolveEventHandler(hostedAppDomain_AssemblyResolve);   **// Exception in this line**

1 个答案:

答案 0 :(得分:0)

想出来......需要改变

setup.ApplicationBase = Assembly.GetExecutingAssembly().CodeBase;

setup.ApplicationBase = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);