dapr / dotnet-sdk

Dapr SDK for .NET
Apache License 2.0
1.11k stars 335 forks source link

Actor serialization doesn't work as dapr client #1050

Open francotiveron opened 1 year ago

francotiveron commented 1 year ago

I am using custom System.Text.Json converters in my dapr application. I set the serialization options to the same value for both dapr client and actors

builder.Services
    .AddControllers()
    .AddDapr(fun daprClientBuider -> daprClientBuider.UseJsonSerializationOptions(App.JsonSerializationOptions) |> ignore)

builder.Services.AddActors(fun actorRuntimeOptions -> actorRuntimeOptions.JsonSerializerOptions <- App.JsonSerializationOptions)

DaprClient calls work as expected with the custom converters

Expected Behavior

Actor calls should also feature the custom converters

Actual Behavior

Actor calls throw serialization exception

System.Runtime.Serialization.SerializationException: Type 'Yatp.Domain.CardValue+Grid' with data contract name 'CardValue.Grid:http://schemas.datacontract.org/2004/07/Yatp.Domain' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.
MattCosturos commented 1 year ago

I believe this is because the dotnet sdk is using the XML DataContractSerializer for Actor to Actor invocation, and the documentation on this is very sparse.