ClientBuildManager抛出AspNetHostingPermission异常

时间:2011-03-24 13:30:41

标签: code-access-security aspnet-compiler

尝试创建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执行的代码的变体,并且可以正常工作

0 个答案:

没有答案