ASP.NET CodeDom provider could not be located error
Asked Answered
C

2

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"/>
Chen answered 8/7, 2019 at 14:46 Comment(0)
C
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>
Cephalopod answered 12/11, 2019 at 12:1 Comment(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 <script runat="server"></script> tags on *.aspx pages. I've spent several hours trying to resolve this. Thank you!Shirtwaist
R
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 !

Reprography answered 28/1, 2022 at 17:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.