繁体   English   中英

ApplicationManager.CreateObject无法在新的AppDomain中加载程序集

[英]ApplicationManager.CreateObject fails to load assembly in new AppDomain

我正在尝试开发一个Web应用程序,该Web应用程序可以根据请求将(Dispatcher)分发到另一个Webapp的多个版本。 为此,我正在使用ApplicationManager.CreateObject来创建运行有问题的Web应用程序的新AppDomain,但是新的应用程序域似乎无法加载Dispatcher的DLL(并且我将DLL复制到了Web应用程序的bin目录,所以我很确定它在那里)。

var version = "version";
var path = @"C:\code\devel\webapp";

// Copy host assembly to target webapp so that 'Host' is available
var assembly = Assembly.GetExecutingAssembly().Location;
var target = path + "\\bin\\" + Path.GetFileName(assembly);
File.Copy(assembly, target, true);

var manager = ApplicationManager.GetApplicationManager();
var obj = manager.CreateObject(version, typeof(Host), "/", path, true, true);

这是融合日志:

Assembly manager loaded from:  c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscorwks.dll
Running under executable  C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = FOOBAR\aaron
LOG: DisplayName = Dispatcher, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///C:/Program Files (x86)/Common Files/Microsoft Shared/DevServer/9.0/
LOG: Initial PrivatePath = NULL
Calling assembly : (Unknown).
===
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Common Files/Microsoft Shared/DevServer/9.0/Dispatcher.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Common Files/Microsoft Shared/DevServer/9.0/Dispatcher/Dispatcher.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Common Files/Microsoft Shared/DevServer/9.0/Dispatcher.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Common Files/Microsoft Shared/DevServer/9.0/Dispatcher/Dispatcher.EXE.

Appbase似乎指向开发服务器的根目录,而不是传递到ApplicationManager.CreateObject的路径,它似乎只是在开发服务器下搜索目录,这似乎很奇怪。 关于如何使新AppDomain在Web应用程序的根目录而不是在开发服务器下搜索DLL的任何想法?

看起来(至少就我们而言)这是错误的方法:使用反向代理是正确的方法。

反向代理的优势在于他们是在HTTP架构的“模式”,他们拯救我们不必确保ASP.NET运行时真的在运行实际的Web应用程序的AppDomain的正确配置。

我们目前正在研究ProxyMachine ,它是一个可高度配置的TCP反向代理, GitHub似乎在此方面取得了一些成功

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM