53

I am using Microsoft Visual Studio 2015, I built a simple website with a C# contact form. When I compile and run on localhost it works perfectly fine. However, when I try to publish it (on smarterasp.net) I am getting an error:

[Win32Exception (0x80004005): Access is denied]

[ExternalException (0x80004005): Cannot execute a program. The command being executed was "..\bin\roslyn\csc.exe"

I have contacted smarterasp.net and they said they dont allow .exe files. I tried to delete csc.exe with ftp from the server but when I do that I am getting the error:

Could not find file "..\bin\roslyn\csc.exe".

How can I solve this issue with the csc.exe that is trying to get included in my project so I can get my this website published?

Community
  • 1
  • 1
Ahron M. Galitzky
  • 2,219
  • 2
  • 13
  • 25
  • What do you publish to your hoster? What kind of files? What kind of VS project did you use? How did you publish it? You normally do not ship csc to your webserver. – Niels V Feb 03 '16 at 18:25
  • It's an MVC project containing html,css,js,cshtml,c#. etc. i published it using the Wed Deploy from within visual studio. – Ahron M. Galitzky Feb 03 '16 at 18:37
  • Hmm.... Do they allow .exe file? This is important. If they allow it, you just need to ask them to give the permission for you. Your applicaiton should be working. –  Feb 19 '16 at 04:30
  • Just change permissions to Read-Write for the /bin folder. Thanks, GuChil for the answer. – Miguel Jan 21 '19 at 02:37

14 Answers14

98

After hours of researching i came up with the solution.

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:

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

This will solve your purpose. Basically this will not generate any csc.exe, vbc.exe files inside bin folder.

I hope it works for you too!

Ahron M. Galitzky
  • 2,219
  • 2
  • 13
  • 25
20

I had this issue on Smarter ASP. On the browser file manager in the control panel, navigate to 'Roslyn' folder in bin and set .net permission to read/write. It worked then.

James Sullivan
  • 201
  • 2
  • 3
17

If you actually want to keep the roslyn codegen, you just need to set the permissions on the application's bin folder to allow the ApplicationPool user Read & Execute.

I did this using the explorer Security tab on the folder properties dialog, but you should also be able to do something like:

icacls PATH_TO_SERVICE_BIN /grant "ApplicationPoolUser":(OI)(CI)RX
Eris
  • 7,378
  • 1
  • 30
  • 45
  • I needed to grant IIS_IUSRS Read on the project site, Read & Execute on the bin. (I just gave it Read & Execute on the entire project site, but that's only for local use.) Thank you! – markau Jun 23 '16 at 06:42
  • 2
    This should be marked as the right answer. This solves the problem at its root, it doesn't just hide the symptoms. – Mike Devenney Mar 06 '17 at 14:26
13

I found the solution as unchecking "Allow precompiled site to be updatable", on publish window. enter image description here

kpr
  • 451
  • 5
  • 17
  • 1
    This won't work if your ASP.NET site relies on the `App_Code` folder. See [this thread](http://stackoverflow.com/questions/24484888/the-directory-website-app-code-is-not-allowed-because-the-application-is-pre) for more information. – Rudey Jan 15 '17 at 16:34
  • Unchecking the "allow precompiled site" box was what finally did it for me. Thanks! – Scott Marlowe Sep 18 '17 at 20:23
  • This works only for websites, but not for web applications – Anytoe Sep 22 '17 at 08:31
  • Thank you. It works perfect for me. I needed DotNetCompilerPlatform, because of C# 6 (Null-conditional Operators), but I am using Godaddy shared hosting :( – Marin Popov Dec 14 '17 at 05:02
12

Just remove the codedom section from the Web.config, this solves the problem.

Himanshu Chauhan
  • 1,181
  • 7
  • 10
12

Just set rw access for /bin folder in Smarterasp.net File Manager as shown below, restart your app

See this image for details

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
GuChil
  • 137
  • 1
  • 6
  • **It does work**. But you have to buy .NET Premium hosting plan in order to run "*.exe" files, like "csc.exe" (Roslyn). – AlexMelw May 29 '18 at 15:52
  • 1
    My current plan is "Advance Plan" and it works. Prev plan is Basic, next is Premium, so currently I can't confirm your point – GuChil May 30 '18 at 07:16
  • You are absolutly right. I've noticed that each [hosting plan](https://image.prntscr.com/image/s74j22qiTnOk02mcpxl6NQ.png) (FREE as well) supports **Full Trust**. Well, it was just a **file permission** issue. Thank you! – AlexMelw May 30 '18 at 17:39
11

Just experienced the same issue as the OP when publishing an ASP.net 4.5.2 SPA via web deploy in VS2015.

The solution I found to work was to remove the Nuget package "Microsoft.CodeDom.Providers.DotNetCompilerPlatform".

You could, alternatively, simply remove the system.codedom compiler config section from your Web.config file, which would have the same affect.

k-dev
  • 909
  • 7
  • 4
1

Here's how I got it working:

  1. In your control panel, navigate to Security Manager > Allow .EXE Files
  2. Set the value to On (this will let you upload .exe files)
  3. In your Web.config, set full trust (this will let you run them)

    <configuration> 
      <system.web> 
        <trust level="Full" /> 
      </system.web> 
    </configuration> 
    
  4. In your publish settings, enable "Precompile during publishing", but in the Advanced Precompile Settings (the Configure link next to this option), disable "Allow precompiled site to be updateable".

aethercowboy
  • 444
  • 4
  • 16
1

I had the same error and I solved it by enable the permissions of the hosting directory (read/write/delete).

1

If you need SmarterAsp.Net to allow the uploading of an .exe file to support the features and functionality of your website, you can. Just go to the control panel and turn on "Allow .Exe Files" See below:

enter image description here

In my case I had to do this because I wanted to host an Asp.Net Core website and that absolutely requires an .exe file :-)

RonC
  • 31,330
  • 19
  • 94
  • 139
0

tl;dr: Ensure that csc.exe is not zero bytes in size.


Longer answer

To add yet another cause and solution: In my case, I got this Yellow Screen Of Death in my browser:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: The compiler failed with error code 255.

c:\windows\system32\inetsrv>C:\inetpub\wwwroot\bin\roslyn\csc.exe /t:library /utf8output /nostdlib+ ...

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

Upon investigation, I isolated the call to csc.exe by executing it inside a CMD window:

c:\inetpub\wwwroot\bin\roslyn\csc.exe

I got this message box:

enter image description here

followed by this line in the CMD window:

Access is denied.

Upon inspecting the files in Windows File Explorer I found out that csc.exe had a size of zero bytes.

I'm unsure at which stage of my deployment script this happens, but after replacing the 0-byte-sized csc.exe with an actual working one, everything works correctly.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
0

The above solutions did not work for me and are not correct, since roslyn is not optional these days.

What worked was ensuring that the pool account had read & execute permissions on the root folder of the web application. You can find the account to grant this permission to by finding the Pool name your web app uses, then Application Pool -> pool name -> Advanced Settings -> Identity.

My VPS host uses non-standard directories for hosting as follows:

c:\home\web.app.name\wwwroot

The web.app.name folder needed the permission.

Herman Schoenfeld
  • 8,464
  • 4
  • 38
  • 49
0

Updating the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to the latest version (at that time) 2.0.1 resolved this issue for me without having to grant permissions to the folder or remove the compiler.

Ahmed Mansour
  • 527
  • 5
  • 13
0

We encountered this due to a 3rd party application. MalwareBytes Anti-Ransomeware was actually the culprit that was blocking access. Resolved this with:

  • Right-click systray icon for MalwareBytes Anti-Ransomeware (not anti-exploit)
  • Stop Protection
Lynn Crumbling
  • 12,985
  • 8
  • 57
  • 95