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?

2

There are 2 best solutions below

3
On

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 created System.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 like int, string, bool. It is very likely that IList<T> wasn't supported at that time. The short answer is try using Newtonsoft.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.

0
On

In addition to Adam Vincent answer. If you want to keep using Newtonsoft.Json in .NET Core 3 you have to install Microsoft.AspNetCore.Mvc.NewtonsoftJson package and in your Startup.cs call AddNewtonsoftJson().

services.AddMvc()
    .AddNewtonsoftJson();