ClientBuildManager 抛出 AspNetHostingPermission 异常
我在尝试创建 ClientBuildManager 实例时遇到奇怪的错误。
这是引发异常的代码:
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";
}
}
这是堆栈跟踪:
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:
我
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:
尝试断言该权限,但似乎没有解决它
事实上,我认为 AspNetHostingPermission 不是根本原因(这里必须缺少其他东西)
奇怪的是,这是由 aspnet_compiler.exe 执行的代码的变体并且可以工作
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论