我发现了很多类似的问题,但找不到任何解决方案。引发AppDomain异常
我有以下代码:
string file = "c:\\abc.dll";
AppDomainSetup ads = new AppDomainSetup();
ads.PrivateBinPath = Path.GetDirectoryName(file);
AppDomain ad2 = AppDomain.CreateDomain("AD2", null, ads);
ProxyDomain proxy = (ProxyDomain)ad2.CreateInstanceAndUnwrap(typeof(ProxyDomain).Assembly.FullName, typeof(ProxyDomain).FullName);
Assembly asm = proxy.GetAssembly(file); // exception File.IO assembly not found is thrown here after succesfully running the funktion GetAssembly.
public class ProxyDomain : MarshalByRefObject
{
public Assembly GetAssembly(string assemblyPath)
{
try
{
Assembly asm = Assembly.LoadFile(assemblyPath);
//...asm is initialized correctly, I can see everything with debugger
return asm;
}
catch
{
return null;
}
}
}
是那么我GetAssembly的Funktion返回一些其他类型的,甚至是我的自定义序列化类最有趣的事情,一切都很好。有人知道我错过了什么吗?或者只是不可能将加载的程序集返回到另一个域?
谢谢
你为什么试图返回一个'Assembly'到父应用程序域?通常,这将被避免,所以父应用程序域不必加载程序集,并且可以在卸载子应用程序域时卸载它。 –
如果你用这个ProxyDomain类来解释你想要达到的目标,这将有所帮助。为什么你需要一个新的AppDomain如果你要返回完整的程序集到你的主域? –
那么,我真的不需要在我的第一个应用程序域中的这个程序集。我在文件夹中有很多它们,我必须找到包含特殊类属性的程序集并返回一个dll名称列表。我需要第二个应用程序域,因为在应用程序重新启动之前,无法删除在主AppDomain中加载的所有程序集。我解决了我的问题,但仍然知道为什么它会返回所有其他类型,并且无法返回Assembly。 – VladL