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

System.ValueTuple does not serialize properly. #17454

Closed
plasticalligator opened this issue Feb 28, 2017 · 4 comments
Closed

System.ValueTuple does not serialize properly. #17454

plasticalligator opened this issue Feb 28, 2017 · 4 comments
Assignees
Labels
Area-Compilers Feature - Tuples Tuples Question Resolution-By Design The behavior reported in the issue matches the current design
Milestone

Comments

@plasticalligator
Copy link

plasticalligator commented Feb 28, 2017

this works fine:
new BinaryFormatter().Serialize(File.Create(Path.GetTempFileName()), new System.Tuple<int, int>(0,0));

this throws "is not marked as serializable":
new BinaryFormatter().Serialize(File.Create(Path.GetTempFileName()), (lat: 0, lon: 0));

In WebAPI: [Route("api/geocoords/usa/zipcodes/{zip}")] public (double lat, double lon) GetZipCoords(int zip) => (0, 0);
returns: {"Item1":0.0,"Item2":0.0}
instead of: {"lat":0.0,"lon":0.0}

Which as you can probably guess is rather disappointing that the new Tuples are almost useless for daily usage in this context.

@RichiCoder1
Copy link

That second issue sounds like a short coming of Json.Net, which handles JSON serialization and deserialization for Web API. I'd create an issue there. You do have to remember that the "friendly" names are largely just compiler magic.

@gafter
Copy link
Member

gafter commented Feb 28, 2017

@jcouv

@jcouv
Copy link
Member

jcouv commented Feb 28, 2017

Regarding the first part ("is not marked as serializable" error):
System.ValueTuple initially shipped without the serializable annotation. This was recently added to the various implementations (mscorlib, coreCLR, coreRT, xamarin) following issue https://github.com/dotnet/corefx/issues/15229. This should work once those implementations ship and you upgrade your target group.
As a demonstration, see the tests added to coreFX.

More details in the umbrella issue for ValueTuple changes.

Regarding the second part (tuple names getting lost):
The element names don't exist in instantiated ValueTuple objects. So I don't expect the names could be preserved by such serialization.

@gafter gafter added this to the 2.1 milestone Feb 28, 2017
@jcouv
Copy link
Member

jcouv commented Feb 28, 2017

@andras-ferencz I will close this issue as by design.
The first part was fixed and will become available as the frameworks ship.
The second part could be discussed with Json.Net, but I expect it cannot be fixed because tuple element names don't exist at runtime.

Feel free to ping me or re-open if this doesn't make sense.

@jcouv jcouv closed this as completed Feb 28, 2017
@jcouv jcouv added the Resolution-By Design The behavior reported in the issue matches the current design label Feb 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Feature - Tuples Tuples Question Resolution-By Design The behavior reported in the issue matches the current design
Projects
None yet
Development

No branches or pull requests

5 participants