[c#] CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default

Kept getting that error when running a fresh ASP.NET MVC application (straight out of VS 2015 Community) on a Windows 2008 Server machine.

This question is related to c# asp.net asp.net-mvc iis

The answer is


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.


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')" />

I found that the direct cause for the error in my case was:

build -> advanced -> language version

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.


If you'd like to use C# 6.0:

  1. Make sure your project's .NET version is higher than 4.5.2.
  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=\&quot;Web\&quot; /optionInfer+" />
 </compilers>
</system.codedom>

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.


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=\&quot;Web\&quot; /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.


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.


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.


in my case (project create in another system):

  1. clean project(right click on project in solution explorer and click clean item).
  2. then build project(right click on project in solution explorer and click build item).

I can run this project.


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=\&quot;Web\&quot; /optionInfer+”>
      <providerOption name=”CompilerVersion” value=”v4.0"/>
  </compiler>
</compilers>


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

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=\&quot;Web\&quot; /optionInfer+" />
 </compilers>
</system.codedom>

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


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


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!


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)

https://developercommunity.visualstudio.com/content/problem/519531/c-7x-versions-do-not-seem-to-work-in-vs2019.html


I've updated the Microsoft.Net.Compilers to version 2.0 or higher

see this


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to asp.net-mvc

Using Lato fonts in my css (@font-face) Better solution without exluding fields from Binding Vue.js get selected option on @change You must add a reference to assembly 'netstandard, Version=2.0.0.0 How to send json data in POST request using C# VS 2017 Metadata file '.dll could not be found The default XML namespace of the project must be the MSBuild XML namespace How to create roles in ASP.NET Core and assign them to users? The model item passed into the dictionary is of type .. but this dictionary requires a model item of type How to use npm with ASP.NET Core

Examples related to iis

ASP.NET Core 1.0 on IIS error 502.5 CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default Publish to IIS, setting Environment Variable IIS Manager in Windows 10 The page cannot be displayed because an internal server error has occurred on server The service cannot accept control messages at this time NuGet: 'X' already has a dependency defined for 'Y' Changing project port number in Visual Studio 2013 System.Data.SqlClient.SqlException: Login failed for user "This operation requires IIS integrated pipeline mode."