CodeDom provider can't be located after another application deployed - asp.net

I had two web applications deployed in a site under IIS 7.5
site.com/myApp
site.com/anotherMyApp
Now another devs deployed their app as root application
site.com/
Now when I access site.com/myApp or /anotherMyApp it throws:
The CodeDom provider type
"Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider,
Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35" could not be
located.
Source error :
Line 54: <system.codedom>
Line 55: <compilers>
Line 56: <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" />
Line 57: <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=\"Web\" /optionInfer+" />
Line 58: </compilers>
Source File: C:\inetpub\wwwrootprettysite\THEIR APPLICATION\web.config
Questions
Why is this happening?
Why is the "source error" in their application's webconfig and how does it affect my application?
How do I fix my applications without breaking theirs?
To clarify :
Application hierarchy is correct, their application should be
installed in root.
.NET framework installed is 4.5.2
Their application is using Roslyn compiler which is supplied in bin/roslyn
My applications web.configs have no <system.codedom> section.

Your app inherits the config from its parent app, and your app doesn't have Microsoft.CodeDom.Providers.DotNetCompilerPlatform. That's why you see that error. There are several options.
Override system.codedom setting in your web.config
Install Microsoft.CodeDom.Providers.DotNetCompilerPlatform nupkg in your app

Related

Problems updating an application in IIS

I have an application written in aspx. The application, launching it from visual studio 2017 works correctly, using any browser.
But when publishing it, and running it on the server, I get the following error:
Parser error message: Could not locate provider type CodeDom "Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35".
I have tried with all the versions available in the Nuget Package Manager and I always get the same error, changing the installed version.
What I do is publish the application in the directory and upload it to any directory on the server. Enter the ASPX of the project and I get that error.
Is there any way to solve this?
The project was already installed previously, and I just have to update the source.
The project settings
The two extensions that give me problems
I have read in multiple sites that changing the version of the CodeDom, and I have followed the instructions to the letter and it has not worked
Just need to comment system.codedom tag in web.config file this work for me. like this
<!--<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.3.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.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>-->

Razor & null propagation - not working under explicit C# 6 MVC 5 project

Current project:
ASP.NET 4.6.2
MVC 5
Visual Studio 2015 Community v14.0.25431.01 Update 3
Installed the CodeDOM Providers for .NET Compiler nuget package via Project -> Install C# 6
Confirmed that I do have the compiler element in my Web.Config and that it is referencing C# 6
My Razor code:
#if(Session["Type"]?.ToString() == "Insurance") {
<text>policy of insurance</text>
} else if(Session["Type"]?.ToString() == "Warranty") {
<text>policy of warranty</text>
} else {
<text>protection policy</text>
}
Visual Studio explicitly flags this with an error,
Feature 'null propagating operator' is not available in C# 5. Please
use language version 6 or greater.
And Visual Studio is explicitly using C# 6:
When I try to run the page itself, I get an error:
CS1525: Invalid expression term '.'
which shows that it is explicitly going after the period following the question mark.
This project was explicitly started as a C# 6 project, and I am quite confused as to why it is derping back to C#5.
Another strange issue: this is working just fine both in debug as well as on my local test setup (I publish to the filesystem, view using local IIS), but when I upload to the server (which has many, many other C#6 sites) it craps out. This is the first razor-side quirk I have ever run across that actually throws an error this badly.
I was having a similar problem and found that I was missing the following from my Web.config file:
<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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>

I cant remove roslyn from published ASP .NET Website using various methods

I am attempting to publish a Webforms website and noticed that the bin folder contains the 'roslyn' subfolder.
After researching it appears that removing 2 nugget packages would resolve the issue.
The problem is that removing the packages doesn't work.
I tried the Nuget package manager console:
uninstall-package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
uninstall-package Microsoft.Net.Compilers
I also tried updating the web.config (and removing the references):
<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=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
I still get the 'roslyn' folder when publishing.
Is this issue possible because the Visual Studio solution was created in a earlier version of VS but the web project was created under VS2015?
I know this is old, but maybe it still helps someone.
The reason you still get the 'roslyn' folder is your .csproj project file. Open it for editing and remove the <Target ...> tag (incl. subtags) referencing the 2 NuGet packages you had to remove the references to.
In my case, there was only one (Microsoft.CodeDom.Providers.DotNetCompilerPlatform), but according to this question, there might be tags for both (see Brian's answer).

How to add a define to an ASP.net solution?

i can add a define to a WinForms project through the Project Properties:
How do i add a define to an ASP.net solution?
Update: Here's what Visual Studio 2010 looks like when working in an ASP.net solution:
Solution Explorer > WebApplicationProject (Name of your Web Application) > Properties > Build:
Have you tried using the compilerOptions attribute of the compilerv element in web.config? Like so:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp"
extension=".cs"
warningLevel="4"
type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
compilerOptions="/define:TRACE">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
....
Should do the trick I think...

Deploying ASP.NET application on IIS 7; got compilerVersion issue

I am trying to deploy two ASP.NET Application onto IIS 7. The first application I copied and pasted under wwwRooT folder and set Application Pool as Asp.NET 4.0 Integrated. For the second one, I created one virtual directory and set the Application Pool the same as the first application.
The first one works well, but the second one got exception:
The value for the 'compilerVersion' attribute in the provider options
must be 'v4.0' or later if you are compiling for version 4.0 or later of the .NET
Framework. To compile this Web application for version 3.5 or earlier of the .NET
Framework, remove the 'targetFramework' attribute from the element of
the Web.config file.
I had a similar problem and had to tell ASP.NET in configuration to use the 3.5 compiler as follows by modifying Web.config.
I've copied and pasted the following from my code. You have to change value="v3.5" to value="v4.0". The compiler type strings might also change.
<configuration>
<!-- ... other configuraiton stuff ... -->
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
<providerOption name="CompilerVersion" value="v3.5"/>
<providerOption name="OptionInfer" value="true"/>
<providerOption name="WarnAsError" value="false"/>
</compiler>
</compilers>
</system.codedom>
</configuration>
In my case the 2.0 compiler was being used instead of 3.5. I was working in an IIS 7, ASP.NET Website project.
You might glean additional insight from:
http://msdn.microsoft.com/en-us/library/system.codedom.aspx
http://msdn.microsoft.com/en-us/library/a15ebt6c%28VS.80%29.aspx

Resources