Reflection 是否在不从文件加载的情况下使用AppDomain.Load(字节[])?
我打破了我的想法。。。我正在尝试使用一个程序集手动加载和卸载域:Reflection 是否在不从文件加载的情况下使用AppDomain.Load(字节[])?,reflection,assemblies,appdomain,.net-assembly,Reflection,Assemblies,Appdomain,.net Assembly,我打破了我的想法。。。我正在尝试使用一个程序集手动加载和卸载域: var domainInfo = new AppDomainSetup { PrivateBinPath = baseDir }; _hostedDomain = AppDomain.CreateDomain("Domain"
var domainInfo = new AppDomainSetup
{
PrivateBinPath = baseDir
};
_hostedDomain = AppDomain.CreateDomain("Domain", null, domainInfo);
_hostedDomain.UnhandledException += HostedDomainUnhandledException;
_hostedDomain.DomainUnload += _hostedDomain_DomainUnload;
var bytes = File.ReadAllBytes("Facade.dll"); // Loads facade from hosts location.
_hostedDomain.Load(bytes);
string asmName = Path.Combine(baseDir, Properties.Settings.Default.AssemblyName);
bytes = File.ReadAllBytes(asmName);
var entryPoint = _hostedDomain.Load(bytes); // exception here!
我看到的是:
当我尝试加载程序集时,我看到系统从CurrentDir/assemblyname.dll加载它(失败)。
异常:System.IO.FileNotFoundException:
无法加载文件或程序集辅助程序,版本=1.0.0.0,区域性=中性,PublicKeyToken=null'或其依赖项之一。系统找不到指定的文件
日志:此绑定在默认加载上下文中启动。
日志:使用应用程序配置文件:D:#开发!test\trunk\bin\Debug\Bootstrapper.vshost.exe.Config
日志:使用主机配置文件:
日志:使用C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config中的计算机配置文件。
日志:此时未将策略应用于引用(私有、自定义、部分或基于位置的程序集绑定)。
日志:正在尝试下载新URLfile:///D:/#Development/!test/trunk/bin/Debug/Worker.DLL。
日志:正在尝试下载新URLfile:///D:/#Development/!test/trunk/bin/Debug/Worker/Worker.DLL。
日志:正在尝试下载新URLfile:///D:/#Development/!test/trunk/bin/Debug/Worker.EXE。
日志:正在尝试下载新URLfile:///D:/#Development/!test/trunk/bin/Debug/Worker/Worker.EXE
顺便说一句,由于限制,无法使用LoadFrom(我遇到了XML序列化的问题……)。
NET到底在做什么?
为什么加载和卸载域如此困难?
谢谢你的帮助 请问一个问题。博客[阅读:别处]是用来咆哮的。不管怎样,我找到解决这个问题的唯一方法就是先创建文件,然后确保文件已加载。有很多关于MSDN的详细文章。我从Sue Mosher那里思考?这种模式不起作用:我有以下结构:Bootstrapper.exe Facade.dll Lib.dll BUILDRESULT\Lib.dll我启动Bootstrapper.exe,如果它从网络获得结果,它将加载BUILDRES\Lib.dll,在其他情况下,它将加载我看到的Lib.dll。如果我尝试使用LoadFrom,它会在类型解析方面引起很多问题:XmlDocument无法转换为XmlDocument,还有更多问题。但如果我使用load()加载,它会以任何方式加载lib.dll。下一个问题-lib.dll没有对bootstrapper.exe的引用,而BUILDRESULT\lib.dll没有对lib.dll的引用,但当我尝试解析BR\lib.dll中的类型时,来宾域希望加载lib.dll。我读了很多文章,无法解决程序集混乱的问题。。