Recently I wanted to use the new ‘null propagating operator’ feature of C# 6.0 in a Razor view.

This resulted in the error message: “Feature ‘null propagating operator’ is not available in C# 5. Please use language version 6 or greater.”, when using Visual Studio even though I was using 2015 edition! When executing the controller/view under IIS I also got the error message:

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: CS1525: Invalid expression term ‘.’

To get this working, I had to add a NuGet package reference to DotNetCompilerPlatform 1.0.1 to my web application project.

PM> Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform

Replacement CodeDOM providers that use the new .NET Compiler Platform (“Roslyn”) compiler as a service APIs. This provides support for new language features in systems using CodeDOM (e.g. ASP.NET runtime compilation) as well as improving the compilation performance of these systems.

To install CodeDOM Providers for .NET Compiler Platform (“Roslyn”), run the following command in the Package Manager Console

After a full solution build, the feature started working.