开发者

ApplicationManager.CreateObject fails to load assembly in new AppDomain

开发者 https://www.devze.com 2022-12-22 09:34 出处:网络
I\'m trying to develop a web application that dispatch (Dispatcher) to multiple versions of another webapp on a per-request basis. To to that end, I\'m using ApplicationManager.CreateObject to create

I'm trying to develop a web application that dispatch (Dispatcher) to multiple versions of another webapp on a per-request basis. To to that end, I'm using ApplicationManager.CreateObject to create new AppDomains running the web app in question, but the new app domains seem to be fail开发者_如何学编程ing to load the Dispatcher's DLL (and I'm copying the DLL over to the web app's bin directory, so I'm pretty sure it's there).

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);

Here's the fusion log:

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.

The Appbase seems to be pointing at the root of the development server, rather than the path passed in to ApplicationManager.CreateObject and it only seems to be searching directories under the development server which seems strange. Any ideas on how to make the new AppDomain search for the DLL in the web app's root rather than under the development server?


It looks like (at least in our situation) this is the wrong way to go: Using a reverse proxy being the right way.

Reverse proxies have the advantage that they are a "pattern" in HTTP architecture and they save us from having to make sure that the ASP.NET runtime is really configured properly in the AppDomains running the actual web app.

We're currently looking at ProxyMachine which is a highly configurable TCP reverse proxy that GitHub seems to have had some success with.

0

精彩评论

暂无评论...
验证码 换一张
取 消