static object CreateWorkerAppDomainWithHost(string virtualPath, string physicalPath, Type hostType)
{
string uniqueAppString = string.Concat(virtualPath, physicalPath).ToLowerInvariant();
string appId = (uniqueAppString.GetHashCode()).ToString("x", CultureInfo.InvariantCulture);
ApplicationManager appManager = ApplicationManager.GetApplicationManager();
Type buildManagerHostType = typeof(HttpRuntime).Assembly.GetType("System.Web.Compilation.BuildManagerHost");
var buildManagerHost = appManager.CreateObject(appId, buildManagerHostType, virtualPath, physicalPath, false);
buildManagerHostType.InvokeMember("RegisterAssembly",
BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic,
null,
buildManagerHost,
new object[2] { hostType.Assembly.FullName, hostType.Assembly.Location });
return appManager.CreateObject(appId, hostType, virtualPath, physicalPath, false);
}