Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater

There is a similar question to this here but I believe that involves a different cause.

I moved a class from a newer project into an older project. Both were targeting .net 4.6 however after the move I received the following error on build.

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater.

I tried setting my project to build with C# 6 in the properties window with no change.

like image 549
TheColonel26 Avatar asked Feb 28 '16 19:02

TheColonel26


People also ask

What is string interpolation in C?

In computer programming, string interpolation (or variable interpolation, variable substitution, or variable expansion) is the process of evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.

Can we use expressions Inside string interpolation?

The string interpolation result is 'Hello, World!' . You can put any expression inside the placeholder: either an operator, a function call, or even more complex expressions. ${n1 + n2} is a placeholder consisting of the addition operator and 2 operands.

Why do we use string interpolation in C#?

The string interpolation feature is built on top of the composite formatting feature and provides a more readable and convenient syntax to include formatted expression results in a result string.

What is variable interpolation in C#?

It is also known as variable substitution, variable interpolation, or variable expansion. It is a process of evaluating string literals containing one or more placeholders that get replaced by corresponding values.

Is the feature 'interpolated strings' available in C5?

Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater There is a similar question to this here but I believe that involves a different cause. I moved a class from a newer project into an older project. Both were targeting .net 4.6 however after the move I received the following error on build.

Is it possible to add interpolated strings in MVC 5?

asp.net mvc 5 - Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. - Stack Overflow Feature 'interpolated strings' is not available in C# 5. Please use language version 6 or greater. The following line does not compile when I put in a Razor View.

Is it possible to get interpolated strings in C4?

Feature 'interpolated strings' is not available in C# 4. Please use language version 6 or greater. - General and Gameplay Programming - GameDev.net Chat in the GameDev.net Discord! Feature 'interpolated strings' is not available in C# 4.

What is string interpolation and when is it available?

This feature is available starting with C# 6. String interpolation provides a more readable and convenient syntax to create formatted strings than a string composite formatting feature. The following example uses both features to produce the same output:


4 Answers

I eventually found the place to change it. It seems sometimes when you update your targets framework version this does not get changed. enter image description here

like image 73
TheColonel26 Avatar answered Oct 17 '22 01:10

TheColonel26


Install DotNetCompilerPlatform version 2.1.0

like image 40
Navid Avatar answered Oct 17 '22 00:10

Navid


(It can applicable VS 2019 - .NET Framework 4.8 Web Application projects easily)

I have realized this issue after install DotNetCompilerPlatform v3.6

I have looked for TheColonel26's answer but I couldn't change selected language version:

Advanced Build Setting - Language Version Selection

Appearantly, we can not change selected language version. (For details look here)

After that I have used kfwbird's answer but with changes for newer version:

 <system.codedom>
     <compilers>
         <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
         <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
     </compilers>
 </system.codedom>

Now it works as should be.

like image 21
bafsar Avatar answered Oct 16 '22 23:10

bafsar


Add this to your web.config. It is probably added automatically after installing DotNetCompilerPlatform.

<system.codedom>
  <compilers>
    <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
    <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
  </compilers>
</system.codedom>
like image 3
kfwbird Avatar answered Oct 16 '22 23:10

kfwbird