I am trying to target .NET 4.6 and also take advantage of the latest C# version by changing the C# language version to 6.
However during compilation I got this error
Open NuGet Package Manager console and run this following command
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
See an answer to ASP.NET strange compilation error!.
Downgrading your C# language to 5 only masks the problem, as soon as someone uses a C# 6 feature your website/project will break and you will still spend time fixing it again. Try the solution in the link.
Update the following NuGet packages (whichever installed) to resolve the problem:
I had similar issue when I was loading application for the first time in visual studio 2019. Updating "Microsoft.CodeDom.Providers.DotNetCompilerPlatform" nuget to later version did the trick for me.
1.Go to Project and select your Project properties.
2 Select Build and Click Advanced Button.
3.Select Language Version default.
4.Save .
https://youtu.be/IP8feQeWqkk
Pay attention to compiler "type" in the Web.Config
file, when changing Framework version:
for 4.5 and C#5 -
type="Microsoft.CSharp.CSharpCodeProvider...
for 4.6 and C#6 -
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
More info in this forum post