Tuesday, July 28, 2015

"System.ComponentModel.Win32Exception: Access is denied"

Problem:

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"

Solution:

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.

Explanation:

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.

20 comments:

  1. Thanks dude, you are my hero today!

    ReplyDelete
    Replies
    1. Excellent! I'm glad I could help. Thanks for letting me know :)

      Delete
    2. This comment has been removed by a blog administrator.

      Delete
  2. Thank you for posting this. You saved me.

    ReplyDelete
  3. Hi Brendan. Thanks for your post. This solution did not work for me, however, but this solution did (per this post on Stack Overflow https://stackoverflow.com/questions/35184429/problems-publishing-a-website-on-smarterasp-net-with-csc-exe-file-included/35207055#35207055 )

    "Since the .NET 4.5 version, Roslyn compilation is the default way of compiling. This means if you create any web application either Web Forms or MVC using .NET 4.5 you get this Roslyn csc.exe compilation pre-installed in your project.

    Basically what i needed was to compile and deploy my project without Roslyn or any .exe files on it.

    So here is the Solution that worked for me. You can deploy without Roslyn with no change in code:

    Open NuGet Package Manager window
    uninstall Microsoft.CodeDom.Providers.DotNetCompilerPlatform package and rebuild & republish. (This uninstallation also removes CodeDom configuration from web.config file.)"

    ReplyDelete
    Replies
    1. Thank you for this info!

      Delete
    2. This comment has been removed by the author.

      Delete
    3. Thank you, uninstalling Microsoft.CodeDom.Providers.DotNetCompilerPlatform works for me

      Delete
  4. Thanks dude. I waste 5 hours to find solution

    ReplyDelete
  5. Thanks for tracking down that solution. Very helpful.

    ReplyDelete
  6. You hero! Excellent work listing the stuff that -didn't- work. May be the answer(s) next time.

    ReplyDelete
  7. Thank you, it's works on my godaddy Web server.

    ReplyDelete
  8. Thank you, it was really helpful!

    ReplyDelete
  9. Thank you very much. It is really helpfully.

    ReplyDelete
  10. really thanks very much you are my hero today too.

    ReplyDelete

Note: Only a member of this blog may post a comment.