[c#] The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider" could not be located

It's a WebApi project using VS2015.

Step to reproduce:

  1. Create an empty WebApi project
  2. Change Build output path from "bin\" to "bin\Debug\"
  3. Run

enter image description here

Everything is working perfectly until I changed Build Output path from "bin\" to "bin\Debug\" In fact, any Output path other than "bin\" won't work.

One little additional thing is that, having another output path to anywhere would work as long as I left a build in "bin\".

Please help providing solution to solve this. I guess that'll cost problem on actual deployment.

This question is related to c# asp.net asp.net-web-api msbuild

The answer is


I know it's an old thread, but I'd like to point the possible version issue of DotNetCompilerPlatform.dll, f. ex. after an update. Please check, if the new generated Web.config file is different as your released web.config, in particular the system.codedom part. In my case it was the version change from 1.0.7 to 1.0.8. The new dll had been already copied to the server, but I didn't change the old web.config (with some server special settings):

<pre>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</pre>

After I update the two lines, the error disappeared.


Another possible solution:

? Restart your Visual Studio Instance with Administrator Rights

enter image description here


If you have been working on a project and this just now popped up as an error. REBOOT your computer (or server in my case) this fixed the issue for me.


If you have recently installed or updated the Microsoft.CodeDom.Providers.DotNetCompilerPlatform package, double-check that the versions of that package referenced in your project point to the correct, and same, version of that package:

  • In ProjectName.csproj, ensure that an <Import> tag for Microsoft.CodeDom.Providers.DotNetCompilerPlatform is present and points to the correct version.

  • In ProjectName.csproj, ensure that a <Reference> tag for Microsoft.CodeDom.Providers.DotNetCompilerPlatform is present, and points to the correct version, both in the Include attribute and the child <HintPath>.

  • In that project's web.config, ensure that the <system.codedom> tag is present, and that its child <compiler> tags have the same version in their type attribute.

For some reason, in my case an upgrade of this package from 1.0.5 to 1.0.8 caused the <Reference> tag in the.csproj to have its Include pointing to the old version 1.0.5.0 (which I had deleted after upgrading the package), but everything else was pointing to the new and correct version 1.0.8.0.


Here are my findings. I also faced this problem today's morning. I just added my current user to application pool on which application was running.

Steps:

  1. Open IIS

  2. Click on application pool

  3. Select your application pool on which you are getting problem

  4. Right Click -> advanced settings

  5. Click on three dot icon beside the identiy

  6. Now select custom account

  7. Give your PC user name and Password

  8. Save

Refresh your application.. and it will start working. There was some security issue for accessing dll.


In My case my web project was not loaded properly ( it was showing project unavailable ) then I had to reload my web project after opening my visual studio in admin mode then everything worked fine.


Just add the next nuget package to your project - Microsoft.CodeDom.Providers.DotNetCompilerPlatform.

Had the same problem.


I have the same problem that my app worked in Vs2013 but getting the error after updating to Vs2015.

  1. In Vs2015, right click project's References folder, to open NuGet Package Manager
  2. Under Browse tab, search for "DotNetCompilerPlatform" and install "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" lib

If your project has Roslyn references and you are deploying it on an IIS server, you might get unwanted errors on the website as many hosting providers still have not upgraded their servers and hence do not support Roslyn.

To resolve this issue, you will need to remove the Roslyn compiler from the project template. Removing Roslyn shouldn't affect your code's functionality. It worked fine for me and some other projects (C# 4.5.2) on which I worked.

Do the following steps:

  1. Remove from following Nuget Packages using command line shown below (or you can use GUI of Nuget Package manager by Right Clicking on Root Project Solution and removing them).

    PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
    PM> Uninstall-package Microsoft.Net.Compilers
    
  2. Remove the following code from your Web.Config file and restart IIS. (Use this method only if step 1 doesn't solve your problem.)

    <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
    


Check whether the BIN folder is uploaded completely or missing in the files.


According to your repro steps, I assumed that changing the output path in the application's property was your only change after you created the application. The only thing this change does is that it tells Visual Studio to put the output assemblies of MSBuild into the new folder. At runtime, however, ASP.Net wouldn't have any idea that it should load assemblies from this new folder instead of the \bin folder.

This answer shows the way to change the build output directory of a WebApi application. To get the exact same error showed in that post, you need to comment out the entire <system.codedom> section in web.config. And then you can follow the instructions to change the output path.

After you get your applicaiton work, you may then uncomment the <system.codedom> section. If you don't use C# 6 new syntax in your application at all you can uninstall the Microsoft.CodeDom.Providers.DotNetCompilerPlatform from you application; otherwise, you may want to add the following command line in your post-build event,

xcopy /Q /Y "$(TargetDir)roslyn\*.*" "$(TargetDir)..\roslyn\"

The new CodeDom provider always looks for the "\roslyn" folder in \bin. The above command works as a workaround and copies the \roslyn folder from your new output folder to \bin.

In my experiments, the publish tool of Visual Studio, however, published the output assemblies to the \bin folder in the deployment location regardless my output path setting. I guess your application should still work on actual deployment.


Here's how I resolved it:

  1. Deleted the bin folder in the project directory.
  2. Click on Build Solution. In VS2017(Run as Admin) > Build > Build Solution.

Ensure Internet Information Services(IIS) is enabled in Windows features on your machine.enter image description here


You should update the "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" and "Microsoft.Net.Compilers" packages in your project .


Regarding this error I've tried:

  • Cleaning and rebuilding the project
  • Unloading and reloading the project
  • Modifying the Target Framework
  • Modifying the Output path
  • Adding nuggets to the GAC
  • Deleting the packages uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform uninstall-package Microsoft.Net.Compilers and installing them again.

While these all seem to be valid solutions, I was only able to generate new errors and in the end, the error seems able to display when certain references/nugets are missing.

In my case, I had recently reinstalled Microsoft Office and was referencing assemblies like Microsoft.Office.Core. The new install didn't seem to include the required packages, which made it so my solution couldn't build correctly.

I was able to solve this issue by reworking my code to the point where I didn't need to reference Microsoft.Office, but could've solved it by looking up the required packages and installing them accordingly.

Seems like an unclear error message from Visual Studio.


Go to inetmgr from start command In IIS manager console choose the application folder under Default Web Site right click on that folder then Convert to Application Run the .asmx file by Enabling It solved the problem


Easy way - Project > Manage NuGet Packages... > Browse(tab) > in search input set this: Microsoft.CodeDom.Providers.DotNetCompilerPlatform

You can install or update or uninstall and install this compiler

DotNetCompilerPlatform


ASP.NET does not search bin/debug or any subfolder under bin for assemblies like other types of applications do. You can instruct the runtime to look in a different place using the following configuration:

<configuration>
   <runtime>   
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin\Debug;bin\Release"/>
      </assemblyBinding>
   </runtime>   
</configuration>

It stopped after publishing on the production server. The reason why it showed me this error was because it was deployed to a subfolder. In IIS i clicked right on the subfolder and excuted "Convert to application" and after this it worked.


I was getting this error because my application pool user was set to ApplicationPoolIdentity. I changed it to a user/service account that has access to the folder and the error went away.


The exception that we ran into was not on the local but on the remote server, the Azure CI was reading it from the packages folder but the compiler versions mentioned above were not found.

To fix this we modified the project file to make it something like

It is not referencing any of the packages here directly referencing the environment variables.

This fixed the issue, however in our cases we don't use packages directly from "package.config" instead we have a separate folder to maintain version integrity across teams.


If you are using git, you are probably ignoring the .dll in the commit


If you see this probably you are building in release mode. For production you should publish instead of building in release mode. For local development build in debug mode.


I had a number of projects in the solution and the web project (problem giving this error) was not set as the StartUp project. I set this web project as the StartUp project, and clicked on the menu item "Debug"->"Start Debugging" and it worked. I stopped debugging and then tried it again and now it’s back working. Weird.


I just had the same problem and it was because I moved the project location and simply needed to recreate the virtual directory.


Be careful of following this answer's advice. While it solves the problem at hand, it might cause different problems at a later date.

I got the same problem. Apparently the .NET compiler was not loaded to the GAC. What I did to solve it was:

First, in the package manager console type:

PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Now, for some reason the nice gentlemen in Microsoft have decided not to install it to the GAC for us. You can do it manually by opening the Developer Command Prompt and typing:

gacutil -i "C:\*PATH TO YOUR APP CODE*\bin\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll"

Conclusion

Microsoft try to encourage everyone to do everything with nugets which could be fine without the occasional bugs you run into with the nuget system. Try to use the same project on different solutions, accidentally (or not) update one of the many nugets it uses on one of them, and if you are unlucky you'll see what I mean when you try to build the other solution. On the other hand, putting files in the GAC can also cause future problems since people tend to forget what they put there and then when setting up new environments they forget to include these files. Another possible solution is to put the files in a central folder for 3rd party dlls (even though it's strange to call the compiler 3rd party), which creates problems of broken references when setting up new environments. If you decide to install the dll to the GAC, use caution and remember that you did so. If you don't, download the nuget for each project again and bear all the annoying bugs being caused by it (at least used to happen when I finally got sick of it and just placed the files in the GAC). Both approaches might give you headaches and create problems, it's just a question of which problems you prefer to deal with. Microsoft recommends to use the nuget system, and generally, it's better to listen to them than to an unknown programmer in SO, unless you are completely sick of the nuget system and used to deal with the GAC long enough for it to be a better alternative for you.


In our case we are using ToroiseSVN and it seems by default the bin folder is not added to the sourcecontrol. So when updating the website on the production server the bin folder was not added to it, thus resulting in this exception.

To add the bin folder to SVN go to the folder on the hdd and find the bin folder. Right click it and select TortoiseSVN --> Add

Now update the repository to include the newly added files and update the production server next. All should be well now.


In my case, I got the error when I had my Web Application in 4.5.2 and the referenced class libaries in 4.6.1. When I updated the Web Application to 4.5.2 version the error went away.


just uninstall the package from package manager console from command below

PM> Uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

PM> Uninstall-package Microsoft.Net.Compilers

and then install it again from nuget manager enter image description here


Make sure your project has fully built!

Click on 'Output' tab and make sure you don't have something like:

========== Rebuild All: 14 succeeded, 1 failed, 0 skipped =========

And open your bin folder and check to see if it's up to date.

I had a whole bunch of typescript errors that I ignored at first, forgetting that they were breaking the build and leading to there being no DLLs copied in.


Add a reference to the CppCodeProvider assembly.


Then the problem came back. I uninstalled both Microsoft.CodeDom.Providers.DotNetCompilerPlatform and Uninstall-package Microsoft.Net.Compilers but no help. Then installed - no help. Cleaned project and built no help. Restarted server no help.Then I noticed the project needed not the latest one which is currently 1.0.5 but 1.0.3 as that was the error could not load the 1.0.3 version. So I installed that dll version instead and now it works.


In my case, this happened when i change the permission of application folder and account IIS_IUSRS has been removed. After i re-added IIS_IUSRS (IIS Manager-> YourWebApp -> Edit Permission -> Add IIS_IUSRS) to the application folder and its worked.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to asp.net-web-api

Entity Framework Core: A second operation started on this context before a previous operation completed FromBody string parameter is giving null How to read request body in an asp.net core webapi controller? JWT authentication for ASP.NET Web API Token based authentication in Web API without any user interface Web API optional parameters How do I get the raw request body from the Request.Content object using .net 4 api endpoint How to use a client certificate to authenticate and authorize in a Web API HTTP 415 unsupported media type error when calling Web API 2 endpoint The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider" could not be located

Examples related to msbuild

How can I install the VS2017 version of msbuild on a build server without installing the IDE? The default XML namespace of the project must be the MSBuild XML namespace The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider" could not be located Visual Studio 2013 error MS8020 Build tools v140 cannot be found Getting msbuild.exe without installing Visual Studio Found conflicts between different versions of the same dependent assembly that could not be resolved This project references NuGet package(s) that are missing on this computer NuGet auto package restore does not work with MSBuild The builds tools for v120 (Platform Toolset = 'v120') cannot be found error LNK2038: mismatch detected for '_MSC_VER': value '1600' doesn't match value '1700' in CppFile1.obj