Skip to content

Serializer errors for dictionaries that don't implement IDictionary #30958

Description

@WayneHiller

Trying to serialize the results of this Dapper query.

var installations = (await Db.QueryAsync<object>( @"select InstallationID AS Value, Name AS Text
                                                   from [AIS].[Abs].Installation" )).ToList();
var inst = JsonSerializer.Serialize( installations );

The error I get is:

Message: 
    System.InvalidCastException : Unable to cast object of type '<GetEnumerator>d__9' to type 'System.Collections.IDictionaryEnumerator'.
  Stack Trace: 
    JsonSerializer.HandleDictionary(JsonClassInfo elementClassInfo, JsonSerializerOptions options, Utf8JsonWriter writer, WriteStack& state)
    JsonSerializer.Write(Utf8JsonWriter writer, Int32 originalWriterDepth, Int32 flushThreshold, JsonSerializerOptions options, WriteStack& state)
    JsonSerializer.WriteCore(Utf8JsonWriter writer, PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
    JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
    JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
    JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)

Should this work? Works fine in Json.Net.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions