Désérialisation échec après la mise à PrefixStyle Fixed32
-
16-09-2019 - |
Question
J'ai une suite de tests pour une bibliothèque de communication que je développe en utilisant protobuf-net
qui exécute bien. passer tous les tests. Mais si je change le PrefixStyle de Base128 à Fixed32, le désérialisation échec.
L'exception que je reçois de la fonction TryDeserializeWithLengthPrefix
est:
System.ArgumentNullException was caught
Message="Value cannot be null.\r\nParameter name: type"
Source="protobuf-net"
ParamName="type"
Tout fonctionne si je garde le simple, PrefixStyle.Base128 lors de la sérialisation et désérialisation le message.
Quelqu'un sait ce qui peut se passer?
La solution
HoHum, yup ressemble à un bug ( maintenant connecté ); exemple reproductible ci-dessous. Je vais voir si je peux le fixer sur le train (peu de temps). Désolé « combat que:
using System;
using System.IO;
using ProtoBuf;
[ProtoContract]
public class Strange // test entity
{
[ProtoMember(1)]
public string Foo { get; set; } // test prop
[ProtoMember(2)]
public int Bar { get; set; } // test prop
static void Main() {
var original = new Strange { Foo = "abc", Bar = 123 };
// serialize and deserialize with base-128
using (MemoryStream ms = new MemoryStream()) {
Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Base128,1);
ms.Position = 0;
object obj;
Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
PrefixStyle.Base128, i => typeof(Strange),out obj);
var clone = (Strange)obj;
Console.WriteLine("Foo via Base128: " + clone.Foo); // works fine
Console.WriteLine("Bar via Base128: " + clone.Bar);
}
// serialize and deserialize with fixed-32
using (MemoryStream ms = new MemoryStream())
{
Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Fixed32,1);
ms.Position = 0;
object obj;
// BOOM here; oh how embarrassing
Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
PrefixStyle.Fixed32, i => typeof(Strange), out obj);
var clone = (Strange)obj;
Console.WriteLine("Foo via Fixed32: " + clone.Foo);
Console.WriteLine("Bar via Fixed32: " + clone.Bar);
}
}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow