I'm having a weird error when trying to create an instance of ClientBuildManager.
Here is the code that throws the exception:
public class createTest
{
public string test()
{
var maxLineLength = 80;
var invalidVirtualPathChars = new char[] { '*', '?'};
PrecompilationFlags _precompilationFlags = new PrecompilationFlags();
string _keyFile = null;
string _keyContainer = null;
var _sourceVirtualDir = "/";
var _sourcePhysicalDir = @"C:\O2\_XRules_Local\_localAspPoCs_2";
var _targetPhysicalDir = @"C:\O2\_XRules_Local\_localAspPoCs_2_Compiled".createDir();
var clientBuildManagerParameter = new ClientBuildManagerParameter();
clientBuildManagerParameter.PrecompilationFlags = _precompilationFlags;
clientBuildManagerParameter.StrongNameKeyFile = _keyFile;
clientBuildManagerParameter.StrongNameKeyContainer = _keyContainer;
var _client = new ClientBuildManager(_sourceVirtualDir,
_sourcePhysicalDir,
_targetPhysicalDir,
clientBuildManagerParameter);
return "ok";
}
}
Here are the stack traces:
Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed. Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
[1:19:21 PM] ERROR: InnerException: at System.Web.Compilation.ClientBuildManager.EnsureHostCreated()
at System.Web.Compilation.ClientBuildManager.get_CodeGenDir()
at O2.Script.createTest.test() in c:\_WorkDir\SI\O2_Scripts\temp\compiler_callback.cs:line 45
at DynamicType.dynamicMethod() StackTrace:
and
at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
at System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
at System.Activator.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.AppDomain.CreateInstance(String assemblyName, String typeName)
at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost开发者_开发技巧, HostingEnvironmentParameters hostingParameters)
at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironmentAndReportErrors(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
at System.Web.Hosting.ApplicationManager.GetAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)
at System.Web.Hosting.ApplicationManager.CreateObjectInternal(String appId, Type type, IApplicationHost appHost, Boolean failIfExists, HostingEnvironmentParameters hostingParameters)
at System.Web.Hosting.ApplicationManager.CreateObjectWithDefaultAppHostAndAppId(String physicalPath, VirtualPath virtualPath, Type type, Boolean failIfExists, HostingEnvironmentParameters hostingParameters, String& appId)
at System.Web.Compilation.ClientBuildManager.CreateHost() StackTrace:
I tried to Assert that permission but it doesn't seem to solve it
In fact I think the AspNetHostingPermission is not the root cause (something else must be missing here)
What is weird is that this is a variation of the code that is executed by the aspnet_compiler.exe and that works
精彩评论