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

Adding codec to serialize F# Unit #9039

Merged
merged 1 commit into from
Jul 8, 2024
Merged

Conversation

gfix
Copy link
Contributor

@gfix gfix commented Jun 10, 2024

When using Unit in Grain interfaces defined in F#, the Silo startup fails with the message Orleans.Serialization.CodecNotFoundException Could not find a codec for type Microsoft.FSharp.Core.Unit. We have previously gotten around this by creating a Surrogate like this in C#

[GenerateSerializer]
public struct UnitSurrogate;

[RegisterConverter]
public sealed class UnitSurrogateConverter : IConverter<Unit, UnitSurrogate>
{
    public Unit ConvertFromSurrogate(in UnitSurrogate surrogate) => null;
    public UnitSurrogate ConvertToSurrogate(in Unit value) => new();
}

This PR tries to add support for serializing Unit directly by creating a Unit codec. The implementation is based on the implementation of the null-case in NullableCodec<T>. I'm note sure the Copier implementation is actually required, as the unit-test succeeds without it.

To test the FSharpUnitCodec I have created a F#-testproject, since I can't use Unit from C#. I have also moved the roundtrip serialization tests for Discriminated Unions to this project. Let me know if this is not desirable.

Microsoft Reviewers: Open in CodeFlow
Copy link
Member

@ReubenBond ReubenBond left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

@ReubenBond ReubenBond merged commit a368d51 into dotnet:main Jul 8, 2024
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants