7

I'm facing an ASP.NET error while deploying on a server:

The CodeDom provider type "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be located.

This error only takes place on a specific server, when executing it locally or on another server it works just fine.

packages.config CodeDom line

  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />

Web.Config CodeDom line

  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Adam Sancho
  • 177
  • 2
  • 2
  • 13

2 Answers2

5

Most likely the project has the Roslyn reference and the IIS server you're deploying on doesn't support it. Either upgrade the server or remove the Roslyn compiler from your project. Removing Roslyn is quite safe and shouldn't affect anything.

To remove Roslyn from your project remove the following Nuget Packages by running the commands:

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

or through Nuget GUI (right-click on the project -> Manage Nuget packages)

If this doesn't help go to your Web.config and remove the following configuration and restart IIS:

<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>
Sergei Russkikh
  • 123
  • 1
  • 7
  • 1
    This helped me figure out why when I attempted to run it locally using Local IIS, I would get this error, but when I used IIS Express, it would run fine. Most importantly to me, switching from using Local IIS to IIS Express returned syntax highlighting, intellisense, type checking, precompiler, etc. to C# code in between `` tags on *.aspx pages. I've spent several hours trying to resolve this. Thank you! – Inphinite Phractals Apr 03 '20 at 20:36
0

In my case I made a web API using Visual Studio 2019, when I opened that solution in VS2022 the compiler was not highlighting the error. I switch back to 2019 and found the compilation issue. Done !