我发现了很多类似的问题,但找不到任何解决方案。
我有以下代码:
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函数返回了一些其他类型,甚至我的自定义可序列化类,一切都很好。有人知道我错过了什么吗?或者只是不可能将加载的程序集返回到另一个域?
谢谢
发布于 2012-12-09 04:01:27
我假设File.IO位于主应用程序的bin目录中?如果是这样的话,您的abc.dll将不知道在哪里可以找到它(除非您的主应用程序也在C:\\中)。
你需要做一个
Bind到AppDomain.AssemblyResolve事件并手动加载引用的dllAppDomainSetup的基目录(这是.NET知道要查找dll的位置之一) File.IO to GAC (这是.NET知道要查找dll的另一个位置)将d17的位置添加到您的AppDomainSetup的专用探测路径(这是d18将尝试查找dll的另一个位置)。<代码>H219<代码>G220
https://stackoverflow.com/questions/13781240
复制相似问题