Kept getting that error when running a fresh ASP.NET MVC application (straight out of VS 2015 Community) on a Windows 2008 Server machine.
-
4Downgrade language version to 5. Take look at: [How to change Language version](http://stackoverflow.com/questions/31912651/how-to-change-language-version-in-visual-studio-2015/31912676#31912676) – NASSER Sep 03 '15 at 15:45
-
1In my case, I have upgraded System.Web.Mvc.dll from version 5.2.3 to 5.2.7, it fixed this issue because the version is incorrect. – Dino Liu Oct 22 '19 at 00:52
-
3In 2019 [a similar error](https://developercommunity.visualstudio.com/content/problem/519531/c-7x-versions-do-not-seem-to-work-in-vs2019.html) occured. See also [this related GitHub issue](https://github.com/aspnet/RoslynCodeDomProvider/issues/67). – Uwe Keim Jul 22 '20 at 07:40
19 Answers
Lots of people are running into it, so I wanted to post here .
Found a crazy easy workaround thanks to this guy: Expertdebugger.
Simply downgrade your language version from C# 6 to C# 5, like so:
<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">
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+">
<providerOption name="CompilerVersion" value="v4.0"/>
</compiler>
</compilers>
</system.codedom>
Change the langversion:6
towards the bottom from 6 to 5 - langversion:5
Fixed it for me. Thank him.

- 39,551
- 56
- 175
- 291

- 7,967
- 5
- 35
- 43
-
1
-
39That is just telling the compiler to compile with C# version 5 instead of 6, which is not what you want if you are making a .NET 4.6 project... What you really need to change is the compiler type, like it is show on the other answer to this question! – Nuno Agapito Nov 25 '15 at 14:23
-
2
-
7
-
2
-
This way can fix the issue, but you should upgrade /specific the compiler instead. – Ray Sep 13 '21 at 05:34
If you'd like to use C# 6.0:
- Make sure your project's .NET version is higher than 4.5.2.
- And then check your
.config
file to perform the following modifications.
Look for the system.codedom
and modify it so that it will look as shown below:
<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>
-
1That's exactly what I was looking for. I began to get this error after upgrading an ASP.NET MVC project from .NET Framework 4.5.2 to 4.6. I'm not sure, but I think that it would be better if Visual Studio updated those lines by itself. – Zignd Nov 05 '15 at 10:36
-
4This should be made the correct answer as it actually fixes the issue and allows the compiler to use the latest version instead of falling back to the old version – SM3RKY Jan 19 '16 at 09:14
-
1Agree with SM3RKY - this answer is more relevant as it solves the issue, rather than bypassing it! – Jon Story Feb 16 '16 at 15:18
-
If you upgrade your solution to .net 4.6 for an existing project using VS 2015 Community or below this error occurs. After updating VS 2015 Update 3, this fix comes by default for the new projects. However the answer is the exact fix! – Mahmut C Jul 19 '16 at 22:45
-
This fixed the issue for me in a .Net 4.6.2 project using ASP.NET (webforms) and VB.NET – Eric Hewett Feb 18 '17 at 11:19
-
Just updated to Visual Studio 2019 16.3.5, .Net 4.8.03761 from an earlier version today. I opened a freshly new solution. I was able to figure out the true error by opening an earlier version of VS and realizing a reference wasnt available. I corrected the reference and built successfully. Opened up VS 2019 again and it worked. – Esaith Oct 21 '19 at 15:32
-
@DavidWoakes That doesn't mean the answer is wrong. It just doesn't apply to your situation. – Toby Caulk Jan 15 '20 at 16:40
-
1This should be marked as the accepted answer. Made sure my framework was 4.6.1; changed the web.config block as shown above; rebuilt correctly. – Jason P Sallinger Sep 23 '21 at 10:30
In my case the error was:
Error CS1617 Invalid option 'latest' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
I opened my .csproj file with notepad and I saw this line:
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>
I changed the latest for an integer in range 1 to 6
<LangVersion>6</LangVersion>
The error disappeared!

- 321
- 2
- 3
-
-
1Need not to be exactly opened in notepad but from visual studion one can upload project and then edit project, which will also fix this problem. – Shantu Jul 15 '19 at 18:57
-
I did not even have LangVersion in my csproj, and when I opened build settings through VS (right click proj->properties->build->advanced) the lang version said "automatically selected based on framework version". Adding LangVersion 6 as suggested in this answer to the csproj's PropertyGroup fixed it for me! – James L. May 19 '21 at 19:27
I found that the direct cause for the error in my case was:
this makes sense since the error is stating that there is an invalid option for language.
but, this was working fine before - so it must've been selected. what changed? turns out a member on my team upgraded to vs 2017, while i was still using 2015. after he made changes to the project, the language version was changed and i received that change over source control. but the version selected was not available to my version of vs, so it was blank - hence the error. after selecting a value in the language drop down (i chose default), a new error popped up. the new error was causing a build failure on any lines of code which used the newer version of c#. i changed the code to perform the same functions, but with my c# version syntax and problem solved.
so while the direct cause of the error was indeed an invalid selection of Language Version, the root cause was due to different vs/c# versions conflicting.

- 589
- 7
- 19
-
1
-
1This answer also applied to my case where I was trying to run a project set to C# 8, but it is not supported in my visual studio 2017. Only VS 2019 – Vinícius Gabriel Aug 09 '20 at 04:09
in my case (project create in another system):
- clean project(right click on project in solution explorer and click clean item).
- then build project(right click on project in solution explorer and click build item).
I can run this project.

- 1,705
- 18
- 25
In my case I was using the wrong MSBuild.exe, the one found in:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319
To resolve the error, I updated my PATH environment variable to start using the Visual Studio 2017 MSBuild.exe:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\MSbuild.exe
Please see this link for details: Error CS1056: Unexpected character '$' running the msbuild on a tfs continuous integration process

- 6,929
- 6
- 66
- 79
-
Same here, in my case I installed the MSBuild Tools and used msbuild from "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" – falstaff Dec 30 '19 at 20:40
Instead of changing the language version from 6 to 5, change the "type" attribute on the compiler tag from
Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
to
Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

- 369
- 4
- 13
Upgrade the Microsoft.Net.Compilers Nuget package to the latest version (at least 2.x)

- 743
- 7
- 16
If above all options are not working and you have used nuget packages like Microsoft.Net.Compilers and CodeDom and still not working then there is issue with your project file open project file. Project file is using one of the compiler option which not support your selected language. Open project file with notepad++ and remove the following line.
Orignal Project File
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\Microsoft.Net.Compilers.Toolset.3.7.0\build\Microsoft.Net.Compilers.Toolset.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.Toolset.3.7.0\build\Microsoft.Net.Compilers.Toolset.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.3.7.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.7.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
<!--Don't delete below one-->
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
Remove The following lines
<Import Project="..\packages\Microsoft.Net.Compilers.Toolset.3.7.0\build\Microsoft.Net.Compilers.Toolset.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.Toolset.3.7.0\build\Microsoft.Net.Compilers.Toolset.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.3.7.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.3.7.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />

- 468
- 7
- 18
-
This is great. It was caused by an old version of the Microsoft.Net.Compilers nuget. – rollsch Feb 02 '21 at 03:47
The easiest solution for me was upgrading the .Net Compilers via Package Manager
Install-Package Microsoft.Net.Compilers
and then changing the Web.Config lines to this
<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>
Turns out this was a problem, because the ASP.NET MVC 4 project was referencing a specific version of the Microsoft.Net.Compilers package. Visual Studio was using the compiler from this specific package, and not the compiler that was installed otherwise on the computer.
A warning or something would have been nice from VS2019 :-)
The solution then is to update the Microsoft.Net.Compilers package to a newer version.
Version 1.x is for C# 6 Version 2.x is for C# 7 Version 3.x is for C# 8 How I got to solve this was not immediately obvious. Visual Studio could have suggested or hinted that by me selecting a new version in the project settings that setting now conflicted with the package installed into the project.
(I ended up turning on Diagnostics level MSBuild logging to find out which CSC.EXE the IDE is really trying to use)

- 461
- 1
- 5
- 11
I was receiving the same error.
In my case the solution was easy.
First, open the properties of your asp.net project,
then click on Typescript Build and validate your typescript version selected.
In my case, the version selected was 2.5 (unavailable),
so with changing this for the Use latest available option, my code was fixed.
Before: TypeScript version with error (image)
After: TypeScript version fixed (image)

- 21
- 4
In my case the error message was:
ASPNETCOMPILER : error CS1617: Invalid option '7.3' for /langversion; must be ISO-1, ISO-2, Default or an integer in range 1 to 6.
As stated in this GitHub issue, and this VS Developer Community post it seems to be a bug in an older Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package.
After upgrading this NuGet package to 3.6.0 the error still persisted in my web application.
Solution
I found out that I had to delete an old "bin\Roslyn" folder in my Web Application to make this work.
It seems that the newer Microsoft.CodeDom.Providers.DotNetCompilerPlatform NuGet package (3.6.0 in my case) does not bring a its own "Rosyln" folder anymore, and if present, that old "Roslyn" folder took precedence during compilation.

- 39,551
- 56
- 175
- 291
I just the changed the langversion
to default
and it worked for me. VS 2015
<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:default /nowarn:1659;1699;1701″>
<providerOption name=”CompilerVersion” value=”v4.0″/>
</compiler>
<compiler language=”vb;vbs;visualbasic;vbscript” extension=”.vb” type=”Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089″ warningLevel=”4″ compilerOptions=”/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+”>
<providerOption name=”CompilerVersion” value=”v4.0″/>
</compiler>
</compilers>

- 303
- 6
- 17
Clean Solution and Build again In my case, whatever the previous settings were blocking due to mismatch. I imported a new project and build it, tried changing versions and all. clean the solutions and build worked for me.

- 201
- 3
- 7
In my case, I was downloading a library with sample code of keycloak implementation by mattorg from GITHUB: https://github.com/mattmorg55/Owin.Security.Keycloak/tree/dev/samples
The solution was quite easy, as I used .Net Framework 4.6.1, but the project begged me in the beginning to use 4.6.2. Although I downloaded it, it was first actively chosen, when restartet all instances of Visual Studion (or better close all instances). The project was manipulated to 4.6.1 (although I wished not and chose so).
So after I chose the configuration again to choose .Net Framework 4.6.1 the error vanished immediately.

- 106
- 7
This happened to me when I pulled down my repo after moving it to a new location. The solution was to unload and then reload each project that was showing this error.
I tried a few other options but nothing worked for me. Also in this situation my config files were set to use languageversion 6, so setting them to default did not fix the issue.

- 857
- 10
- 11
For me I deleted a line (<LangVersion>7.3</LangVersion>
) in .csproj file from property group
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'MyProject|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Myproject\</OutputPath>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
And now all works fine. .Net Framework must have possibility to select alone which version of C# need to be used.

- 311
- 4
- 15