orleans
orleans copied to clipboard
Adding codec to serialize F# Unit
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.