Skip to content

Orleans serialization errors with nullable ValueObject<string> fields #887

@Lukazoid

Description

@Lukazoid

Describe the bug

Was originally using Orleans 9, now Orleans 10 and the issue still occurs.
Using latest stable Vogen 8.0.4.

Steps to reproduce

With the following value object definition and request contract:

[ValueObject<string>]
public readonly partial record struct OrderId;

[GenerateSerializer]
public sealed record GetOrderRequest
{
    [Id(0)]
    public OrderId? OrderId { get; init; }
}

When I specify a non-null value for OrderId e.g. OrderId = OrderId.From("XYZ") I get the following from Orleans:

Orleans.Serialization.ReferenceNotFoundException : Reference with id 3 and type System.Nullable`1[GrainContracts.Orders.OrderId] not found.
   at Orleans.Serialization.Codecs.NullableCodec`1.ThrowInvalidReference(UInt32 reference) in /_/src/Orleans.Serialization/Codecs/NullableCodec.cs:line 62
   at Orleans.Serialization.Codecs.IFieldCodec`1.Orleans.Serialization.Codecs.IFieldCodec.ReadValue[TInput](Reader`1& reader, Field field) in /_/src/Orleans.Serialization/Codecs/IFieldCodec.cs:line 54
   at Orleans.Runtime.Messaging.MessageSerializer.ReadBodyObject[TInput](Message message, Reader`1& reader) in /_/src/Orleans.Core/Messaging/MessageSerializer.cs:line 142
   at Orleans.Runtime.Messaging.MessageSerializer.TryRead(ReadOnlySequence`1& input, Message& message) in /_/src/Orleans.Core/Messaging/MessageSerializer.cs:line 110
   at Orleans.Runtime.Messaging.Connection.ProcessIncoming() in /_/src/Orleans.Core/Networking/Connection.cs:line 294
--- End of stack trace from previous location ---
   at Orleans.Serialization.Invocation.ResponseCompletionSource`1.GetResult(Int16 token) in /_/src/Orleans.Serialization/Invocation/ResponseCompletionSource.cs:line 230
   at System.Threading.Tasks.ValueTask`1.ValueTaskSourceAsTask.<>c.<.cctor>b__4_0(Object state)
--- End of stack trace from previous location ---

I believe what is happening is that the Orleans NullableCodec only ever serializes the "null" value as WireType.Reference (see NullableCodec), so when the Vogen codec then decides to send a string reference, it doesn't get read back correctly.

Expected behaviour

Nullable fields of string primitives to round-trip successfully with Orleans.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions