Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am getting error: Execution permission cannot be acquired while running asp.net site.

Background:
I create a Asp.net-4.0 site with MySQL db.
It was working fine on my local machine(OS Window 7 Home basic).
But when I deploy my site on server, it was not connecting to MySQL database.
After discover the issue with tech-support of Host-provider, we came to conclusion that its a issue of trust level.
On Hosting-server they allow trust level = Medium, whereas I have created my site with trust level = Full.

Then after I change trust level to medium after modified machine level web.config under "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config"

But now I am getting below error on my local machine.
HTML
Server Error in '/' Application.

Execution permission cannot be acquired.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Security.Policy.PolicyException: Execution permission cannot be acquired.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[PolicyException: Execution permission cannot be acquired.]
   System.Security.CodeAccessSecurityEngine.TryResolveGrantSet(Evidence evidence, PermissionSet& grantSet) +10848962
   System.Security.CodeAccessSecurityEngine.ResolveGrantSet(Evidence evidence, Int32& specialFlags, Boolean checkExecutionPermission) +44

[FileLoadException: Could not load file or assembly 'App_Code.o1k1ykzn, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416)]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0
   System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +34
   System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +152
   System.Reflection.Assembly.Load(AssemblyName assemblyRef, Evidence assemblySecurity) +34
   System.CodeDom.Compiler.CompilerResults.get_CompiledAssembly() +98
   System.Web.Compilation.CodeDirectoryCompiler.GetCodeDirectoryAssembly(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories, Boolean isDirectoryAllowed) +9761311
   System.Web.Compilation.BuildManager.CompileCodeDirectory(VirtualPath virtualDir, CodeDirectoryType dirType, String assemblyName, StringSet excludedSubdirectories) +125
   System.Web.Compilation.BuildManager.CompileCodeDirectories() +382
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +252

[HttpException (0x80004005): Could not load file or assembly 'App_Code.o1k1ykzn, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416)]
   System.Web.Compilation.BuildManager.ReportTopLevelCompilationException() +62
   System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled() +427
   System.Web.Compilation.BuildManager.CallAppInitializeMethod() +31
   System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException) +535

[HttpException (0x80004005): Could not load file or assembly 'App_Code.o1k1ykzn, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. PolicyException thrown. (Exception from HRESULT: 0x80131416)]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9950728
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237


Please suggest solution
Thank in advance
Posted

1 solution

So, your app wanted trust "full", but the production host wouldn't let it - understandable.
So you lowered the trust on your app to match the production host - perfect.

But then you app wouldn't work on your development machine - because it expects full trust, not medium.

Reconfigure your development system so that you app doesn't need full trust (or use two web.config files - one for dev and one for production: you should anyway to support the different connection strings if nothing else)
 
Share this answer
 
Comments
Sagar Khairnar 55 19-Apr-15 4:14am    
Hi sir,
Thanks for your support.
Can you please explain the last paragraph (Reconfigure...if nothing else) in detail, I am bit confuse in getting the solution, also how to use two web.config or reconfigure development system!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900