orleans icon indicating copy to clipboard operation
orleans copied to clipboard

Adding codec to serialize F# Unit

Open gfix opened this issue 8 months ago • 0 comments

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

gfix avatar Jun 10 '24 11:06 gfix