Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mono (C#) Tuple support #34803

Closed
jasonswearingen opened this issue Jan 4, 2020 · 3 comments
Closed

Mono (C#) Tuple support #34803

jasonswearingen opened this issue Jan 4, 2020 · 3 comments

Comments

@jasonswearingen
Copy link

Godot version:
v3.2-beta4_mono_win64

OS/device including version:
Win10 (PC) using VSCode

Issue description:

Mono 6.x is supposed to support the C# 7.0 Tuple types, but it doesn't work. VSCode shows errors and trying to run the scene in Godot also errors with identical error messages.

When I try to paste in the example from https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-7#tuples

(string Alpha, string Beta) namedLetters = ("a", "b");
Console.WriteLine($"{namedLetters.Alpha}, {namedLetters.Beta}");

VSCode outputs errors:

{
	"resource": "/c:/repos/godot/projects/Godot basic Move and Dodge Game CSharp/scripts/Steve.cs",
	"owner": "csharp",
	"code": "CS8137",
	"severity": 8,
	"message": "Cannot define a class or member that utilizes tuples because the compiler required type 'System.Runtime.CompilerServices.TupleElementNamesAttribute' cannot be found. Are you missing a reference? [Godot basic Move and Dodge Game CSharp]",
	"source": "csharp",
	"startLineNumber": 29,
	"startColumn": 3,
	"endLineNumber": 29,
	"endColumn": 30
}

//and
{
	"resource": "/c:/repos/godot/projects/Godot basic Move and Dodge Game CSharp/scripts/Steve.cs",
	"owner": "csharp",
	"code": "CS8179",
	"severity": 8,
	"message": "Predefined type 'System.ValueTuple`2' is not defined or imported [Godot basic Move and Dodge Game CSharp]",
	"source": "csharp",
	"startLineNumber": 29,
	"startColumn": 3,
	"endLineNumber": 29,
	"endColumn": 30
}

I looked in my Godot_v3.2-beta4_mono_win64\GodotSharp\Mono\lib\mono\4.5 folder and don't see a System.Runtime.CompilerServices.dll so maybe that's it? (though there is System.Runtime.CompilerServices.Unsafe.dll)

I'm sorry but I'm new to Godot and Mono so not sure if this is something I could workaround on my end (install my own version of Mono?) or if there is another problem.

I tried installing the System.ValueTuple Nuget package (another error mentioned) but that didn't help.

Steps to reproduce:

	public override void _Ready()
	{
		(string Alpha, string Beta) namedLetters = ("a", "b");
		Console.WriteLine($"{namedLetters.Alpha}, {namedLetters.Beta}");
}

Minimal reproduction project:

if you need a project, let me know, but as it's more regarding Mono+VSCode+Project I think that wouldn't help much.

@jasonswearingen
Copy link
Author

Did some more research but I'm at a loss. However this comment by Mr Zagaeski [MSFT] might be helpful: https://developercommunity.visualstudio.com/solutions/121139/view.html

@jasonswearingen
Copy link
Author

jasonswearingen commented Jan 4, 2020

I got it working. it turns out I didn't follow the steps to install nuget packages properly.

What I did (That did not work) was:

  1. Using VSCode's Nuget Package Manager Extension I added "System.ValueTuple" v4.5
  2. from command prompt I ran dotnet restore (the extension recommended I do this to install the nuget package)
  3. Adjust the <Version> tag as per: Adding a nuget package makes Godot not build #30970 (comment)

The problem is, dotnet restore seems to change the .csproj in some way that corrupts it for mono use. after doing this I couldn't get it building again (either in VSCode or Godot) so something about this is incompatable with Mono it seems. (I have a feeling it's something like CRLF or BOM tweaking)

This workflow WORKED:

  1. Using VSCode's Nuget Package Manager Extension I added "System.ValueTuple" v4.5
  2. downloaded the nuget.exe from it's website and ran nuget restore (which is NOT what VSCode suggests you do!)
  3. Adjust the <Version> tag as per: Adding a nuget package makes Godot not build #30970 (comment)

Doing that, now Tuples are working in my project:

	public override void _Ready()
	{
		var tuple = (first: "hello", second: "godot!!!");
		var (third, fourth) = ("goodbye", "godot");
		GD.Print($"{tuple.first}, {tuple.second} .... {third} {fourth}");
	}

So maybe you can add some documentation telling people not to use dotnet restore (and the <Version> workaround) to this doc page? https://docs.godotengine.org/en/latest/getting_started/scripting/c_sharp/c_sharp_basics.html#using-nuget-packages-in-godot

EDIT: I submitted a pull request to update these docs.

@jasonswearingen
Copy link
Author

jasonswearingen commented Jan 4, 2020

admins: feel free to close this, just please consider mentioning the proper workflow in docs (see the last paragraph of my last comment)

Edit: (I submitted a pull request, as linked below)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants