Invalid Option ‘7.3’ For /langversion; Must Be ISO-1, ISO-2, Default

This is one of the common errors we face in ASP.NET from time to time. This compiler error occurs sometimes because of version changes where the Dotnet compiler version and C# version are incompatible.

Exact Error

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

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

In short, we will below error in the compiler.

Compiler Error Message - Invalid option ‘7.3’ for /langversion; must be ISO-1, ISO-2, Default, Latest, or a valid version in range 1 to 7.1.

Solution 1

One of the easy solutions is to install and reinstall these two NuGet packages.

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

Right Click on Project >> Manage NuGet Packages >> Installed as shown,

Manage NuGet Packages

Simply, uninstall and install again these packages.

Solution 2. Another way is to update the following NuGet packages (whichever installed) to resolve the problem,

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

Solution 3: 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.DotNetCompilerPlatfor

Workaround: Change in webconfig,

<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.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>

Attribute  “compilerOptions” needs to be replaced: “langversion:6” -> ‘langversion:5“

This is how we can solve this compilation error.