问题描述
我正在将我的2.2 .net核心Web应用程序升级到3.1构建成功,但是
swagger无法加载并发送消息Failed to load API deFinition.
,当我检查Web请求时发现此错误
Schema cannot be generated for type System.Collections.Generic.Dictionary`2[foonamespace.fooclass,System.Collections.Generic.Dictionary`2[System.String,System.String]] as it's not supported by the System.Text.Json serializer2at Swashbuckle.AspNetCore.SwaggerGen.JsonSerializerDataContractResolver.
public Dictionary<Foo,Dictionary<string,string>> AdditionalData { get; set; }
有人知道如何解决
解决方法
尝试一下:https://github.com/dotnet/runtime/issues/30524#issuecomment-524619972,但作者具体说
'但是它仍然无法序列化嵌套的Dictionary,例如 字典
>因为System.Text.Json没有 接受内部类型Dictionary '
因此,在您的代码中,我认为这是不可能的。在.Net 5.0上,system.text.json可以使用,但是在那之前,唯一的解决方案是使用NewtonsoftJson。