Skip to content

Deserializing inherited class throws exception #114824

@ray440

Description

@ray440

Description

Deserializing an inherited F# class throws an exception:

Reproduction Steps

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

Expected behavior

No exception

Actual behavior

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 --- 

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions