You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
string json = System.Text.Json.JsonSerializer.Serialize(new Dictionary<int, int>());
Throws an exception
System.NotSupportedException
HResult=0x80131515
Message=The collection type 'System.Collections.Generic.Dictionary`2[System.Int32,System.Int32]' is not supported.
Source=System.Text.Json
StackTrace:
at System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, Type implementedPropertyType, PropertyInfo propertyInfo, Type parentClassType, JsonConverter converter, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.AddProperty(Type propertyType, PropertyInfo propertyInfo, Type classType, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo.AddPolicyProperty(Type propertyType, JsonSerializerOptions options)
at System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializerOptions.GetOrAddClass(Type classType)
at System.Text.Json.WriteStackFrame.Initialize(Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.WriteCore(Utf8JsonWriter writer, Object value, Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.WriteCore(PooledByteBufferWriter output, Object value, Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.WriteCoreString(Object value, Type type, JsonSerializerOptions options)
at System.Text.Json.JsonSerializer.Serialize[TValue](TValue value, JsonSerializerOptions options)
at ConsoleApp18.Program.Main(String[] args) in C:\Users\x\source\repos\ConsoleApp18\ConsoleApp18\Program.cs:line 11
The text was updated successfully, but these errors were encountered:
My understanding is that this is currently by design in 3.x.
There's a good discussion of this issue you can follow in #30524. This may be a duplicate of that issue (though the issue title could be updated for clarity).
The current state is that there is a proposal in progress, see #32676
The following code
string json = System.Text.Json.JsonSerializer.Serialize(new Dictionary<int, int>());
Throws an exception
The text was updated successfully, but these errors were encountered: