🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

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

Started by
4 comments, last by Shaarigan 3 years ago

I'm working on augmented reality project on MAC OS

While running one of the files of my project

I keep getting the error

>Error CS8025: Feature 'interpolated strings' is not available in C# 4. Please use language version 6 or greater. (CS8025)

I already using visual studio 2019 and everything is up to date

tried to follow some answers on another topic but nothing helps me

Advertisement

not using visual studio or mac, but by the looks of it there are at least 3 paths you can try.

1. Assuming you can configure the C# version used in the project, did you verify using the correct version?

2. I would expect “CS8025 fix" to be searchable at the Internet with explanations how to fix. This holds pretty much for any standard problem, you're not the first one encountering it, and people write about everything at the Internet.

3. While “interpolated strings” may not be supported, I am sure you can make strings in C# versions 1-5. Find out how, and change the code so you don't use interpolated strings.

Interpolated strings

$"Hello, {name}! Today is {date.DayOfWeek}, it's {date:HH:mm} now."

are compiler magic and so not supported up to certain compiler version. The compiler simply decides to replace them with either of String.Concat or String.Format in worst case (like the one above).

I'm not a MAC pro but make sure to use the right MSBuild version as it depends on what version of CSC or Roslyn is used and so what features are available. There might be something with your MSBuild installation or project settings being wrong and MSBuild version can unfortunately not be changed in the Editor. You have to open the .csproj file in a text editor (it is XML) and see if there are some strange MSBuild or Build targets defined.

It may also depend on the .NET version used.

Anyways, it would be easier to not be lazy and build those strings by your own with one of the above methods

The C# version is generally* tied to the .NET version. C#4 being from .NET 4.0 over a decade ago.

Updating your project to .NET Framework 4.8 will give you C#7, .NET Core 3 has C #8 and .NET 5 has C #9 (but Core and .NET 5 migration is a bit more complex). Some versions in between will be C#5 and C#6 by default, I didn't check.

*You can use a newer version in some cases by editing the project file in some cases, this gives you access to features added that are compiler only and don't need runtime support. Use the <LangVersion> tag, I don't believe there is UI support in Framework projects in VS2019 so edit manually. See https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version

There are also libraries you can add to enable some additional features, this can get complex and I only looked up a few cases (e.g. Nullable package to get some attributes into .NET Framework and Standard for C# 8 nullable feature).

SyncViews said:
The C# version is generally* tied to the .NET version

This isn't right. If you have a .NET version installed which shippes also with a new version of the CSC - C# Compiler and building from command line using that CSC version, you can achieve up to C# 5 or so. If you're building using Visual Studio, they come with their own MSBuild and Roslyn versions installed in the VS directory. Those may, depending on the VS version, support up to C# 7. The newer .NET Core 5 (aka .NET 5) framework also has it's own CSC aka Roslyn compiler included in every version, so it depends on what version of the Core Framework you're using. A .NET 5 project built with .NET 5.0.100 might be trageting C# 8 while a newer version tragets probably C# 9 or higher.

It is not necessary tangled to the .NET version as you can use .NET 4 with C# 4 as target platform in VS, but due to the fact you use VS 2019 it will in fact build with C# 5 or even higher and you can get async/await running in .NET 4 as well when adding your own implementation of the necessary types used when the compiler generates the async state machine, which are added in .NET 4.5 for the first time

This topic is closed to new replies.

Advertisement