Avinash Jain
Avinash Jain

Reputation: 7616

Compilation Error when change .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition

After changing my .Net framework from 4.5.2 to 4.5 in VS 2015 Community edition. I am getting following error. Did anyone know what is the issue and how to solve this. Look like compile version is different, but I have already modify my web.config to 4.5

Server Error in '/' Application.

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]

Source File: Line: 0

Show Detailed Compiler Output:

C:\Program Files (x86)\IIS Express> "C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Users\admin\AppData\Local\Temp\Temporary ASP.NET Files\root\479d40ee\add72695\assembly\dl3\31bb6ea7\6a8168a8_dae8d001\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll" /R:"C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll" /R:"C:\WINDOWS...................

Microsoft (R) Visual C# Compiler version 4.6.0079.0

for C# 5 Copyright (C) Microsoft Corporation. All rights reserved.

This compiler is provided as part of the Microsoft (R) .NET Framework, but only supports language versions up to C# 5, which is no longer the latest version. For compilers that support newer versions of the C# programming language, see http://go.microsoft.com/fwlink/?LinkID=533240

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

Upvotes: 11

Views: 46883

Answers (4)

Muhammad Ahmad
Muhammad Ahmad

Reputation: 11

This solution also worked for me. Window 10 Visual studio 2013 .Net framework 4.5

Go to each project property -> Build -> Advance and change the language version to C# 5.0 Open web.config for the startup project (MVC in my case) and remove the codedom section that contain the custom compile information This fix my issue.

Upvotes: 0

Dai
Dai

Reputation: 155608

C# in Visual Studio 2015 is C# 6.0, however the error message you're getting is from the ASP.NET Compiler (not the Visual Studio compiler) informing you that C# 6.0 is not available, only C# up-to version 5, so not version 6.

I suspect this error message is coming from your webhosting provider, which means they haven't installed the very latest version of the .NET Framework on their systems, you'll need to downgrade your C# language compilation options in your web.config back to what they were before and refrain from using any C# 6.0 language features in runtime-compiled code. I don't know what effect running C# 6.0 language-features in a .NET 4.5.0 environment will have if they rely on any new CLR instructions.

Update:

Alternatively, ensure you're using the latest version of the Microsoft.Net.Compilers NuGet package, which causes the latest version of csc to be bundled with your project when deployed, so it will have support for C# 6, 7, 8, etc.

Upvotes: 5

Avinash Jain
Avinash Jain

Reputation: 7616

I am answering my question just to let other user know what's the solution. After some googling and personal research. So I precisely did two thing.

  • Go to each project property -> Build -> Advance and change the language version to C# 5.0
  • Open web.config for the startup project (MVC in my case) and remove the codedom section that contain the custom compile information

This fix my issue.

Upvotes: 14

Daniele D.
Daniele D.

Reputation: 2744

I was facing the same building with MSBuild and the following helped me:

In Visual Studio > Select your project > Right Click > Properties > Library > Targeting > Change > .Net Framework 4.6

This link Helped me

Upvotes: 0

Related Questions