Celtic Coding Solutions Blog

Celtic Coding Solutions Blog - for everything computer related

Visual Studio Compiler error after changing application .Net target framework

Wrote an Asp.Net application using latest Visual Studio 2015 and target framework of .Net 4.5.2. but needed to re-compile it using just .Net 4.5 same as on the web server.  Usually fairly simple just open Applications Project properties and change the Target Framework, re-compile and any errors will be apparent.  However on running the Web App I see the following in the Browser:-

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

Source Error:

[No relevant source lines]

Fix:-

Kind of tells you why it is failing in the Compiler Error Message so check your Web.Config.  Find the section on <compilers> and check that is is correct.

Mine looked like this:-

<compilers>

  <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=4.0.0.0, Culture=neutral, warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701">

  <providerOption name="CompilerVersion" value="v4.0"/>

</compiler>


Everything looks OK but the issue is in the section:-
compilerOptions="/langversion:6 /nowarn:1659;1699;1701"
So change this to:-
compilerOptions="/langversion:5 /nowarn:1659;1699;1701"

Recompile and all will be working again.
Comments are closed