Tuesday, July 28, 2015

"System.ComponentModel.Win32Exception: Access is denied"


The following error is encountered after publishing a website:
System.ComponentModel.Win32Exception: Access is denied[Win32Exception (0x80004005): Access is denied]
[ExternalException (0x80004005): Cannot execute a program. The command being executed was "E:\someDirectory\myWebsite.com\wwwroot\bin\roslyn\csc.exe"


Change the .NET application's framework version to 4.5.
Also erase  the <compiler> section from the web.config if it's throwing an error when you build.


This happened to me when running Visual Studio 2015, and publishing my website with a .NET version of 4.5.2, on my Personal Class ASP server on Arvixe. I noticed the problem did not happen when I was using a different computer with an older version of Visual Studio 2015 CTP. I noticed that the non-working version of VS was setting the target framework to 4.5.2, but the version of VS that was working for me had it set to 4.5.

The version that did not work is:

Microsoft Visual Studio Enterprise 2015
Version 14.0.23107.0 D14REL
Microsoft .NET Framework
Version 4.6.00081

The version that did work is:

Microsoft Visual Studio Ultimate 2015 CTP
Version 14.0.22609.0 D14REL
Microsoft .NET Framework
Version 4.6.00030

To fix this, open up Visual Studio. Open the Solution Explorer.

Right click on "WebApplication1" (or whatever you named your app) and then click on "Properties".
You'll be presented with the following window.
Ensure that "Target Framework" is set to 4.5. Hit Ctrl+S to save.

If you previously built with a target framework of 4.5.2, you may have a <compiler> section in your web.config, and this may throw an error when you build. Just remove this section to fix the issue. Removing it should not cause any problems.

That solved it for me. It may not solve it for you depending on the configuration of IIS on the server you're deploying to. If it didn't work, check below for other things I tried that didn't work for me but may work for you!

Other things I tried that didn't work:

  • In IIS, Enabled Basic Authentication, disabled Integrated Windows Authentication.
  • In VS when publishing using Web Deploy, I selected to exclude app_data files.
  • Tried running VS as admin
  • In IIS, checked "Enable write permissions" and "enable directory browsing",
  • Deleted everything from wwwroot and published again
  • Changed platform target from "any cpu" to x86 in web application build settings.
  • Changed platform target from "any cpu" to x64 in web application build settings.