Skip to content

Fix DataRecord serialization#6619

Open
ElectroJr wants to merge 1 commit into
space-wizards:masterfrom
ElectroJr:fix-record-struct-seri
Open

Fix DataRecord serialization#6619
ElectroJr wants to merge 1 commit into
space-wizards:masterfrom
ElectroJr:fix-record-struct-seri

Conversation

@ElectroJr

Copy link
Copy Markdown
Member

DataRecord serialization is pretty broken at the moment. Default values are ignored for structs (see #6556) and simple records using floats or negative default values will cause SerializationManager.CreateRecordInstantiator() to generate invalid IL. E.g., neither of these work:

[DataRecord] public partial record Foo(float A);
[DataRecord] public partial record Bar(int A = -1);

I've tried to fix both of these issues, and added a bunch more tests, but I'm not super confident that I've got all the edge cases and the code is somewhat convoluted. I'm also not that confident in writing IL code, and mostly worked backwards by looking at actual IL that got generated when manually calling record constructors.

Fixes #6556

Comment on lines -107 to 114
if (type.IsValueType)
if (isRecord)
{
CreateValueTypeInstantiator(generator, type);
CreateRecordInstantiator(generator, type);
}
else if (isRecord)
else if (type.IsValueType)
{
CreateRecordInstantiator(generator, type);
CreateValueTypeInstantiator(generator, type);
}

@ElectroJr ElectroJr Jun 6, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching these if blocks is what actually fixes #6556. Without this, the constructors of DataRecord structs are basically just ignored.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Deserializing record structs doesn't respect default arguments.

1 participant