У меня странная ошибка при попытке создать экземпляр 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 и который работает