我正在升级我的应用程序以使用 .Net Core 2 和 .NetStandard。 在几个方面,我正在序列化ClaimsIdentity
以用于记录和传输目的。
每当我尝试序列化包含至少一个声明的ClaimsIdentity
时,我都会得到一个PlatformNotSupportedException
。 我怀疑这是由于 .Net Core 2 (https://github.com/dotnet/corefx/issues/23415) 中引入的二进制序列化更改。 这似乎以前已经解决 (https://github.com/JamesNK/Newtonsoft.Json/issues/1404) 但是我在 11.0.2 中仍然收到此错误。
使用反编译器,在发生了错误OnSerializingMethod
在方法ClaimsIdentity
,并且仅当所述身份具有附着1项或多个权利要求发生:
[OnSerializing]
private void OnSerializingMethod(StreamingContext context)
{
if (this is ISerializable)
{
return;
}
_serializedNameType = _nameClaimType;
_serializedRoleType = _roleClaimType;
if (_instanceClaims != null && _instanceClaims.Count > 0)
{
throw new PlatformNotSupportedException(SR.PlatformNotSupported_Serialization); // BinaryFormatter would be needed
}
}
System.Security.Claims.ClaimsIdentity
一个完全序列化的对象,所有声明都完好无损。
PlatformNotSupportedException: This instance contains state that cannot be serialized and deserialized on this platform.
var identity = new ClaimsIdentity();
identity.AddClaim(new Claim("test", "test"));
var serializedIdentity = JsonConvert.SerializeObject(identity);
这看起来像ClaimsIdentity
的预期行为。 与 corefx 团队一起提出。
我们有解决这个问题吗?
这个问题解决了吗?
此问题尚未解决。
.net 核心 3.1