Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

C#.Netasp.net Mvc-5.2.Net 4.6

C# Problem Overview


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:

> Error Invalid option '6' for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

If I update the /langversion:6 in Web.Config setting to 5 it works,

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">

But how do I resolve this without resorting to lower language version?

I am using Visual Studio 2015 Community Edition, and I have also installed .NET Framework 4.6 manually just in case it was not installed by default by Visual Studio 2015.

The project is a standard ASP.NET MVC template project created by Visual Studio 2015.

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

Update the following NuGet packages (whichever installed) to resolve the problem:

  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • Microsoft.Net.Compilers

Solution 3 - C#

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">https://youtu.be/IP8feQeWqkk</a>

Solution 4 - C#

Open NuGet Package Manager console and run this following command

Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r

Solution 5 - C#

I met such behavior if project was not fully upgraded to VS2015. In case if you open solution from 2015 in VS2013 - you will get this error

Solution 6 - C#

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.

Solution 7 - C#

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRosdi KasimView Question on Stackoverflow
Solution 1 - C#DrewBView Answer on Stackoverflow
Solution 2 - C#DeveloperView Answer on Stackoverflow
Solution 3 - C#Prashant vishwakarmaView Answer on Stackoverflow
Solution 4 - C#Mahfuj Ur RahmanView Answer on Stackoverflow
Solution 5 - C#Sergii LischukView Answer on Stackoverflow
Solution 6 - C#GovindView Answer on Stackoverflow
Solution 7 - C#PBoView Answer on Stackoverflow