我需要帮助找出为什么BinaryFormatter不能反序列化标识:
var identities = new[]
{
new ClaimsIdentity("Bug")
{
Actor = new ClaimsIdentity("Bootstrap Context as a string")
{
BootstrapContext = "this causes issue"
},
BootstrapContext = new BootstrapContext("this raw token")
}
};
var sessionToken = new SessionSecurityToken(new ClaimsPrincipal(identities));
byte[] buffer;
using (var ms = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(ms, sessionToken);
buffer = ms.ToArray();
}
using (var ms = new MemoryStream(buffer))
{
var formatter = new BinaryFormatter();
sessionToken = (SessionSecurityToken)formatter.Deserialize(ms);
}这将导致带有内部消息的异常TargetInvocationException:
“无法将'System.String‘类型的对象强制转换为System.String类型我无法自行调试Framework,因此我请求您的帮助找出这种意外行为的根源。
发布于 2013-12-16 06:59:05
BootstrapContext属性在ClaimsIdentity中为Object类型。这意味着您可以为它分配一个字符串(就像您所做的那样)。但是,阅读文件 --您可以看到它实际上应该是一个BootstrapContext对象,这可能是反序列化过程中所期望的。
https://stackoverflow.com/questions/20605045
复制相似问题