protobuf-net

Protobuf-net fails to serialize property with only getter - Cannot apply changes to property

梦想与她 提交于 2019-12-18 06:37:31
问题 I am using protobuf-net to serialize an object and I get exception: Cannot apply changes to property TestProject.TestMessage.ClientId with stacktrace: at ProtoBuf.Serializers.PropertyDecorator.SanityCheck(TypeModel model, PropertyInfo property, IProtoSerializer tail, Boolean& writeValue, Boolean nonPublic, Boolean allowInternal) at ProtoBuf.Serializers.PropertyDecorator..ctor(TypeModel model, Type forType, PropertyInfo property, IProtoSerializer tail) at ProtoBuf.Meta.ValueMember

Protobuf-net fails to serialize property with only getter - Cannot apply changes to property

风格不统一 提交于 2019-12-18 06:37:22
问题 I am using protobuf-net to serialize an object and I get exception: Cannot apply changes to property TestProject.TestMessage.ClientId with stacktrace: at ProtoBuf.Serializers.PropertyDecorator.SanityCheck(TypeModel model, PropertyInfo property, IProtoSerializer tail, Boolean& writeValue, Boolean nonPublic, Boolean allowInternal) at ProtoBuf.Serializers.PropertyDecorator..ctor(TypeModel model, Type forType, PropertyInfo property, IProtoSerializer tail) at ProtoBuf.Meta.ValueMember

serializing a Dictionary<string,object> in ProtoBuf-net fails

自作多情 提交于 2019-12-18 04:12:58
问题 (NOTE: Dictionary where T is some ProtoContract / ProtoMembered class works fine. ) This issue only happened for me with type object. I was trying to serialize a dictionary of Dictionary working. typeof(object) doesn't work. Should it? Should I implement a string based work around? In this scenario, object will only ever be a .net primitive. [Test] public void De_SerializeObjectDictionary2() { var d = new Dictionary<string, object>(); d.Add("abc", 12); var ms = new MemoryStream(); var model =

protobuf-net serializing object graph

十年热恋 提交于 2019-12-18 02:18:32
问题 If I have object A and B both contain some field serialized field F, and both point to the same serializable object C. Does protobuf-net serialize by reference or serialize by value? When the object graph is deserialized, does protobuf-net generate 2 separate objects for A.F and B.F? I'm asking because I want to know if serialization preserves reference equality. 回答1: The raw "protobuf" spec, a defined by Google, is a tree serializer (like XmlSerializer). So by default you would get C

How to serialize a closed immutable type with protobuf-net?

拈花ヽ惹草 提交于 2019-12-17 20:38:39
问题 For example, I would like to serialize and deserialize System.Drawing.Font which is immutable and cannot be altered to suit protobuf-net conventions. In general, is it possible to write some sort of "custom" serializer in protobuf-net? Edit : Based on the accepted answer, here are examples of proxies for System.Drawing : [ProtoContract] struct ProtoColor { [ProtoMember(1, DataFormat=DataFormat.FixedSize)] public uint argb; public static implicit operator Color(ProtoColor c) { return Color

XML vs Binary performance for Serialization/Deserialization

◇◆丶佛笑我妖孽 提交于 2019-12-17 19:44:16
问题 I'm working on a compact framework application and need to boost performance. The app currently works offline by serializing objects to XML and storing them in a database. Using a profiling tool I could see this was quite a big overhead, slowing the app. I thought if I switched to a binary serialization the performance would increase, but because this is not supported in the compact framework I looked at protobuf-net. The serialization seems quicker, but deserialization much slower and the

protobuf and List<object> - how to serialize / deserialize?

做~自己de王妃 提交于 2019-12-17 19:05:56
问题 I have a List<object> with different types of objects in it like integers, strings, and custom types. All custom types are protobuf-adjusted. What I wanna do now is to serialize / deserialize this list with protobuf.net. Up until now I suspect that I have to declare each and every type explicitly, which is unfortunately not possible with these mixed-list constructs. Because the binary formater has no problems to do these things I hope that I missed something and that you can help me out. So

protobuf-net inheritance

♀尐吖头ヾ 提交于 2019-12-17 18:25:03
问题 Marc mentioned on stackoverflow that it will be possible in v2 of protobuf-net to use ProtoInclude attribute (or similar approach) to serialize/deserialize class hierarchy without a need to specify each subtype in the base class. Is this implemented yet? We have a plugin interface that can be derived in external libraries, so there is no way of knowing what the derived types will be. We could maintain unique numbering between types though, but I couldn’t find any examples on the net, short of

How to choose between protobuf-csharp-port and protobuf-net

巧了我就是萌 提交于 2019-12-17 17:25:38
问题 I've recently had to look for a C# porting of the Protocol Buffers library originally developped by Google. And guess what, I found two projects owned both by two very well known persons here: protobuf-csharp-port, written by Jon Skeet and protobuf-net, written by Marc Gravell. My question is simple: which one do I have to choose ? I quite like Marc's solution as it seems to me closer to C# philisophy (for instance, you can just add attributes to the properties of existing class) and it looks

Deserialize unknown type with protobuf-net

荒凉一梦 提交于 2019-12-17 10:38:22
问题 I have 2 networked apps that should send serialized protobuf-net messages to each other. I can serialize the objects and send them, however, I cannot figure out how to deserialize the received bytes . I tried to deserialize with this and it failed with a NullReferenceException. // Where "ms" is a memorystream containing the serialized // byte array from the network. Messages.BaseMessage message = ProtoBuf.Serializer.Deserialize<Messages.BaseMessage>(ms); I am passing a header before the