简短的回答是不可能做到这一点,但是Cassini消息来源揭示了另一种解决方案。
更新
上面的链接不再有效,但是 CodePlex 上的CassiniDev 项目似乎非常接近(可能是衍生作品)并且包含相同的解决方案。
解决方案是避免使用CreateApplicationHost
和“自己做”——在这种情况下,使用反射来创建内部“BuildManagerHost”类型的实例并调用“RegisterAssembly”,就像这样
/// <remarks>
/// This is Dmitry's hack to enable running outside of GAC.
/// There are some errors being thrown when running in proc
/// </remarks>
private object CreateWorkerAppDomainWithHost(string virtualPath, string physicalPath, Type hostType,int port)
{
// create BuildManagerHost in the worker app domain
//ApplicationManager appManager = ApplicationManager.GetApplicationManager();
Type buildManagerHostType = typeof(HttpRuntime).Assembly.GetType("System.Web.Compilation.BuildManagerHost");
IRegisteredObject buildManagerHost = ApplicationManager.CreateObject(_appId, buildManagerHostType, virtualPath,
physicalPath, false);
// call BuildManagerHost.RegisterAssembly to make Host type loadable in the worker app domain
buildManagerHostType.InvokeMember("RegisterAssembly",
BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
null,
buildManagerHost,
new object[] { hostType.Assembly.FullName, hostType.Assembly.Location });
// create Host in the worker app domain
// FIXME: getting FileLoadException Could not load file or assembly 'WebDev.WebServer20, Version=4.0.1.6, Culture=neutral, PublicKeyToken=f7f6e0b4240c7c27' or one of its dependencies. Failed to grant permission to execute. (Exception from HRESULT: 0x80131418)
// when running dnoa 3.4 samples - webdev is registering trust somewhere that we are not
return ApplicationManager.CreateObject(_appId, hostType, virtualPath, physicalPath, false);
}