升级到 .net core 2.1,现在我无法序列化声明

Upgraded to .net core 2.1 and now I can't serialize a claim

我目前在两个 Azure 微服务之间发送声明(System.Security.Claims.Claim 类型)。当我使用 .net Core 2.0 时,它运行良好。服务结构通信层按预期序列化和反序列化。当我升级到 .net core 2.1 时,我现在收到错误:

System.Runtime.Serialization.InvalidDataContractException: 'Type 'System.Security.Claims.Claim' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.'

我看到您通过单独的声明类型来回答这个问题。不确定 .NET 声明类型发生了什么变化,但它必须有。 https://fuget.org/packages/System.Security.Claims/4.3.0/lib/netstandard1.3/diff/4.0.1/ 不会立即显示任何内容,可能必须真正拆解才能看到差异。

您还可以通过拥有一个您可以控制并且更宽松的自定义序列化程序来解决这个问题。这对您自己的类型特别有效,因为您可以显式控制该过程。

更多信息在这里:https://docs.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-reliable-collections-serialization#custom-serialization