How to use C# 8.0 with Godot 3.3.2?

I am trying to use the System.Range and System.Index classes with new C# v8.0 construct, see (here). But, I cannot make it work. I have tried under Windows with .NET 5.0 and under Ubuntu with Mono 6 but I got the same result:

First I have changed the .csproj file like that:

<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<TargetFramework>net472</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>


Note the <LangVersion> set at 8.0. With that parameter, I can now build the project with this kind of snippet:

int[] nb = {1, 2, 3};
GD.Print(nb[1..2]);


But at runtime, I got this error: Predefined type 'System.Range' is not defined or imported

@aimo: I had to add using System.Runtime to make the project able to build.

@Theraot: I had tried to change target framework to .net5.0 (that was only possible on Windows). The project was still able to build but the error at runtime was different:

E 0:00:01.563   debug_send_unhandled_exception_error: System.TypeLoadException: Could not resolve type with token 01000010 from typeref (expected class 'System.Range' in assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a')
<C++ Error>   Unhandled exception
<C++ Source>  modules/mono/mono_gd/gd_mono_utils.cpp:423 @ debug_send_unhandled_exception_error()


But this answer made me think that the Mono assemblies used at runtime needs net472.

Another hint is that an important Godot project that claims to use C# v8.0, the beautiful Thrive, sets net472 and 8.0 in their config file (see here)

• Do you need some using directive to access that feature? Or is it really built into the core language? This site claims Godot can use C# 8.0: docs.godotengine.org/en/stable/getting_started/scripting/… – Almo Jun 7 at 21:13
• I know little of custom .NET SDKs, but after looking at the source it appears the SDK is based on .NET Standard 2.0, while - according to Microsoft documentation - this requires .NET standard 2.1, .NET Core 3.0 or .NET 5.0 - Also Godot claims to support C# 8.0 and .NET 5.0 (according to Godot 3.3 release notes) - Thus, I'd say open an issue. Edit: wait, hold on, did you change target framework? You say you tried .NET 5.0 but your code snippet says net472. – Theraot Jun 7 at 21:26
• I have edited the answer according to your remarks. – pietrodito Jun 8 at 5:46

The issue was coming from TargetFramework!

If the option .net5.0 is not supported by Godot, there is another option to have full System.Runtime feature of C# v8 netstandard2.1:

<Project Sdk="Godot.NET.Sdk/3.3.0">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>
</Project>


The answer was given by a user called 31 on Github and Discord (see the closed issue here).