Skip to content

Exception when deserializing inherited type from json #61540

@ray440

Description

@ray440

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Trying this:

type Animal() = class end

type Foo() = 
	inherit Animal()
	member val Name = "init" with get, set

let js  = """{"Name":"Ed"}"""
let x = System.Text.Json.JsonSerializer.Deserialize<Foo>(js)  // zzz not good

Threw this:

AmbiguousMatchException: Multiple custom attributes of the same type 'Microsoft.FSharp.Core.CompilationMappingAttribute' found. 
   at System.Attribute.GetCustomAttribute(MemberInfo element, Type attributeType, Boolean inherit) 
   at System.Text.Json.Serialization.Metadata.FSharpCoreReflectionProxy.IsFSharpType(Type type) 
   at System.Text.Json.Serialization.Converters.FSharpTypeConverterFactory.CanConvert(Type typeToConvert) 
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetBuiltInConverter(Type typeToConvert) 
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.GetConverterForType(Type typeToConvert, JsonSerializerOptions options, Boolean resolveJsonConverterAttribute) 
   at System.Text.Json.Serialization.Metadata.DefaultJsonTypeInfoResolver.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 --- 
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Nullable`1 ensureNotNull, Boolean resolveIfMutable, Boolean fallBackToNearestAncestorType) 
   at System.Text.Json.JsonSerializerOptions.GetTypeInfoForRootType(Type type, Boolean fallBackToNearestAncestorType) 
   at System.Text.Json.JsonSerializer.GetTypeInfo[T](JsonSerializerOptions options) 
   at System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options) 
:
--- End of stack trace from previous location --- 

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions