92

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.

3
  • 1
    In my case I only had to remove /langversion:6... Dec 7, 2015 at 9:36
  • @modosansreves That will revert to default language version.. which is C# 5 I believe... please check whether you can use any of C# 6 language feature. Dec 7, 2015 at 10:34
  • Indeed. This deprives of using C# 6 features. Thanks. Dec 7, 2015 at 12:24

6 Answers 6

91

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

5
  • 20
    This works!.. Although I consider it as a bug in Visual Studio 2015 for not updating this automatically when I re-target my application to .NET 4.6 and C# 6. Aug 14, 2015 at 11:41
  • I think you're right in that. I got stung with it and stumbled across your question. Luckily the next link I found was the answer.
    – DrewB
    Aug 15, 2015 at 4:38
  • 1
    Is there universal CSharpCodeProvider for all .NET targets?
    – denfromufa
    Sep 11, 2017 at 16:19
  • 2
    My web.config had correct type and language version was set to default <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" /> Just cleaning the solution and recompiling fixed it for me in VS 2019.
    – joym8
    Mar 30, 2020 at 19:30
  • This doesn't really tell users what to change or where exactly it is, let alone why.
    – TylerH
    Nov 2, 2022 at 22:30
39

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

  • Microsoft.CodeDom.Providers.DotNetCompilerPlatform
  • Microsoft.Net.Compilers
1
  • I switched to c# 6.0, but the package was still on an older version. Updating from 1.0 to 1.0.4 worked for me.
    – Mixxiphoid
    May 13, 2017 at 23:48
14

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

2
  • Had this error in VS2013. This solution didn't work for me unfortunately.
    – Jviaches
    Jul 17, 2017 at 20:30
  • 2
    This one worked for me. All the other suggested solutions revolved around changing the web.config file, or alternatively, downloading NuGet packages / updates. The compiler kept throwing errors about an invalid version, which confused me since I hadn't had that setting in the config file. Turns out the advanced build properties wasn't automatically updated by the NuGet package update. Nov 11, 2017 at 22:33
4

Open NuGet Package Manager console and run this following command

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

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

1
  • Me too, I think this error basically means you need to install VS2015! Someone else on the project is using newer language features that 2013 can't cope with
    – JonnyRaa
    Oct 6, 2017 at 11:46
0

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.