code-access-security


ClientBuildManager throws AspNetHostingPermission exception


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

Related Links

PHP Web page (code) access security
Consolidating Code Access Security
How to secure source files of a project?
Code theft prevention - Chaperon or anything similar
ClientBuildManager throws AspNetHostingPermission exception
Remote email/license verification idea for digital software upgrader
Adding a license key to a zip file
System.Type.GetCustomAttributes on an assembly loaded from a network share is not showing all attributes

Categories

HOME
ionic-framework
jdo
bluetooth
netsuite
azure-data-factory
drivers
hp-exstream
sqlite-net-extensions
spring-cloud-stream
spring-jdbc
yarn
sharepoint-designer
ravendb
azure-media-services
ios-charts
synchronization
nano-server
clearcase-ucm
footer
reactive-cocoa
undefined
tar
csrf-protection
kvc
smb
intel-pin
linkerd
applozic
replaceall
titanium-mobile
catch-all
avcapturesession
dosbox
dartium
objectlistview
streamreader
preconditions
rainbowtable
typescript1.8
git-diff
nstextview
forever
mako
imanage
django-scheduler
blacklist
query-performance
quartz-composer
angular-cache
home-directory
py2app
disque
skype4py
qcustomplot
xpath-1.0
pervasive-sql
tcpserver
content-length
coveralls
ibaction
facebook-graph-api-v2.4
fscommand
gadt
flask-cors
article
bundles
srs
fmod
ril
gridcontrol
html4
chronoforms
plasma
ocunit
angularjs-controller
path-separator
parametric-equations
netdna-api
gwt-ext
mongomapper
radcombobox
substrings
virtual-functions
thread-local-storage
3gp
rtml

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App