I have project .net core 2.2.
in 2.2 my controller's return type is List<Dictionary<Guid, string>>
.
When I upgrade my project to 3.1 it returns the error message.
System.NotSupportedException
HResult=0x80131515
Message=The collection type 'System.Collections.Generic.Dictionary`2[System.Guid,System.String]' is not supported.
Source=System.Text.Json
Why is this error message showing? How to fix it?
It appears that in upgrading to .NET Core 3, you have inadvertently switched JSON serializers. The primary JSON serializer in the early days of .NET Core was
NewtonSoft.Json
, then the dotnet team createdSystem.Text.Json
.System.Text.Json
, at the time of .NET Core 3 had limited type support. If I recall correctly, at that time it only supported primitive types likeint
,string
,bool
. It is very likely thatIList<T>
wasn't supported at that time. The short answer is try usingNewtonsoft.Json
instead to serialize / deserialize this type. The long answer is don't use a version of .NET that has long passed its life cycle.