Estoy en el proceso de actualizar mi aplicación para usar .Net Core 2 y .NetStandard. En varias áreas estoy serializando un ClaimsIdentity
para fines de registro y transmisión.
Siempre que intento serializar un ClaimsIdentity
que contiene al menos un reclamo, obtengo un PlatformNotSupportedException
. Sospecho que esto se debe a los cambios de serialización binaria introducidos en .Net Core 2 (https://github.com/dotnet/corefx/issues/23415). Esto parece haberse solucionado anteriormente (https://github.com/JamesNK/Newtonsoft.Json/issues/1404), sin embargo, sigo recibiendo este error en 11.0.2.
Usando un descompilador, el error ocurre en el método OnSerializingMethod
en ClaimsIdentity
, y solo ocurre cuando la identidad tiene 1 o más reclamos adjuntos:
[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
Un objeto completamente serializado con todas las reclamaciones intactas.
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);
Parece el comportamiento esperado de ClaimsIdentity
. Créalo con el equipo de corefx.
¿Conseguimos una resolución para esto?
¿Se resolvió esto?
Este problema no se ha resuelto.
.net core 3.1