我在 asp.net core 3.0 preview 8 中编写了一个 rest api,我试图使用新的“System.Text.Json”类序列化一个 System.Data.DataTable,但是在 Serialize 方法中我收到了异常:
不支持“System.Data.DataTable.ChildRelations”上的集合类型“System.Data.DataRelationCollection”。
使用 newtonsoft json 序列化程序,相同的序列化效果很好。
重现问题的示例代码:
var dt = new System.Data.DataTable("test");
dt.Columns.Add("Column1");
var ser=System.Text.Json.JsonSerializer.Serialize(dt);
详细异常:
System.NotSupportedException HResult=0x80131515 Message=不支持“System.Data.DataTable.ChildRelations”上的集合类型“System.Data.DataRelationCollection”。Source=System.Text.Json StackTrace: 在 System.Text.Json.JsonClassInfo.GetElementType(Type propertyType, Type parentType, MemberInfo memberInfo, JsonSerializerOptions options) at System.Text.Json.JsonClassInfo.CreateProperty(Type declaredPropertyType, Type runtimePropertyType, Type在 System.Text.Json.JsonClassInfo.AddProperty(Type propertyType, PropertyInfo propertyInfo, Type classType, JsonSerializerOptions options) 在 System.Text.Json.JsonClassInfo..ctor(Type type, JsonSerializerOptions选项)在 System.Text.Json。
你能帮忙吗?
谢谢你。