Skip to content

NullabilityInfoContext is not thread safe #4

@anhaehne

Description

@anhaehne

The shared NullabilityInfoContext in JsonTypeInfoExtensions can cause InvalidOperationException.

See: dotnet/runtime#100254

Logs:

Connection id "0HNHQOODTUGBM", Request id "0HNHQOODTUGBM:00000198": An unhandled exception was thrown by the application.
      System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct.
         at System.Collections.Generic.Dictionary`2.FindValue(TKey key)
         at System.Reflection.NullabilityInfoContext.GetNullableContext(MemberInfo memberInfo)
         at System.Reflection.NullabilityInfoContext.GetNullabilityInfo(MemberInfo memberInfo, Type type, NullableAttributeStateParser parser, Int32& index)
         at System.Reflection.NullabilityInfoContext.Create(PropertyInfo propertyInfo)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfoExtensions.CreateJsonPropertyInfo(JsonTypeInfo typeInfo, PropertyInfo propertyInfo, String name)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfoExtensions.AddJsonPropertyInfo(JsonTypeInfo typeInfo, PropertyInfo propertyInfo, String name)
         at HAL.Common.Converters.ResourceOfTJsonConverterFactory.GetTypeInfo(Type type, JsonSerializerOptions options)
         at System.Text.Json.Serialization.Metadata.JsonTypeInfoResolverChain.GetTypeInfo(Type type, JsonSerializerOptions options)
         at System.Text.Json.JsonSerializerOptions.GetTypeInfoNoCaching(Type type)
         at System.Text.Json.JsonSerializerOptions.CachingContext.CreateCacheEntry(Type type, CachingContext context)
      --- End of stack trace from previous location ---

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions