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

Dapr fails to deserialize items when calling into statestore #1407

Closed
WTW-Jacob-Evans opened this issue Nov 15, 2024 · 1 comment
Closed
Labels
kind/bug Something isn't working

Comments

@WTW-Jacob-Evans
Copy link

Expected Behavior

When making multiple singular calls to the statestore, each item is deserialized correctly.

Actual Behavior

When retrieving multiple items from the statestore, Dapr will not be able to deserialize the same types if there are multiples of those types in the statestore.

System.ArgumentException: An item with the same key has already been added. Key: MainApp.DTOs.ChartSectionDto
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Text.Json.InterfaceConverter`1.GetCustomType(String typeName)
   at System.Text.Json.InterfaceConverter`1.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options)
   at System.Text.Json.Serialization.JsonConverter`1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value, Boolean& isPopulatedValue)
   at System.Text.Json.Serialization.JsonConverter`1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state)
   at System.Text.Json.JsonSerializer.ReadFromSpan[TValue](ReadOnlySpan`1 utf8Json, JsonTypeInfo`1 jsonTypeInfo, Nullable`1 actualByteCount)
   at System.Text.Json.JsonSerializer.Deserialize[TValue](ReadOnlySpan`1 utf8Json, JsonSerializerOptions options)
   at Dapr.Client.TypeConverters.FromJsonByteString[T](ByteString bytes, JsonSerializerOptions options)
   at Dapr.Client.DaprClientGrpc.GetStateAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)

Steps to Reproduce the Problem

Make multiple calls into the statestore for a stored object that are all of the same type.
image
This shows the calls that were made. 4 were successful, and 2 failed, with the 2 being the same type as 1 of the 4 successful ones.

I think its likely the specific shape of the object, as they all inherit from a base interface that has [JsonInterfaceConverter(typeof(InterfaceConverter<ISection>))] (you can see the actual exception is coming from the interface converter), although I have not observed this before. Is there anything specific to the Dapr deserialization that could cause this?

I wrapped the calls in a semaphore as a test and it deserialized fine.

Any help is appreciated, the issue is very strange.

@WTW-Jacob-Evans WTW-Jacob-Evans added the kind/bug Something isn't working label Nov 15, 2024
@WTW-Jacob-Evans
Copy link
Author

Ignore this, the InterfaceConverter was actually a random package that was sharing the System.Text.Json namespace, removed and replaced with JsonPolymorphicType all good now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant