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

C#asp.netasp.net MvcIis

C# Problem Overview


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

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

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>

Solution 3 - C#

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!

Solution 4 - C#

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.

Solution 5 - C#

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.

Solution 6 - C#

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: https://stackoverflow.com/questions/42932577/error-cs1056-unexpected-character-running-the-msbuild-on-a-tfs-continuous-i

Solution 7 - C#

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

Solution 8 - C#

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

Solution 9 - C#

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

Solution 10 - C#

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>

Solution 11 - C#

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

Solution 12 - C#

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)

Solution 13 - C#

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

see this

Solution 14 - C#

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>

Solution 15 - C#

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.

Solution 16 - C#

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.

Solution 17 - C#

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.

Solution 18 - C#

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.

Solution 19 - C#

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.

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
QuestionKyle CarlsonView Question on Stackoverflow
Solution 1 - C#Kyle CarlsonView Answer on Stackoverflow
Solution 2 - C#chswordView Answer on Stackoverflow
Solution 3 - C#nahuelmiscView Answer on Stackoverflow
Solution 4 - C#Heriberto LugoView Answer on Stackoverflow
Solution 5 - C#Ali RasouliView Answer on Stackoverflow
Solution 6 - C#user8128167View Answer on Stackoverflow
Solution 7 - C#Nwachukwu A. NnaemekaView Answer on Stackoverflow
Solution 8 - C#wnbatesView Answer on Stackoverflow
Solution 9 - C#AliView Answer on Stackoverflow
Solution 10 - C#MikeView Answer on Stackoverflow
Solution 11 - C#B1zzleView Answer on Stackoverflow
Solution 12 - C#Victor M. SarmientoView Answer on Stackoverflow
Solution 13 - C#davcupView Answer on Stackoverflow
Solution 14 - C#KumarView Answer on Stackoverflow
Solution 15 - C#Sumanstm21View Answer on Stackoverflow
Solution 16 - C#peddaView Answer on Stackoverflow
Solution 17 - C#Uwe KeimView Answer on Stackoverflow
Solution 18 - C#Brendan SlukeView Answer on Stackoverflow
Solution 19 - C#BASKAView Answer on Stackoverflow