I have below class :-
[Serializable]
[DataContract(Name = "StateValueWrapper")]
public class StateValueWrapper
{
[DataMember(Order = 1)]
public Type StateValueType { get; set; }
[DataMember(Order = 2)]
public object WrappedObj { get; set; }
}
I am trying to serialize the object of above class using protobuf.net.While serializing getting an error "No suitable Default Type encoding found." please suggest me what i need to do for this? Below is my code for serilization:-
MemoryStream ms = new MemoryStream();
var srariazeObj = new StateValueWrapper();
srariazeObj.StateValueType = typeof(int);
srariazeObj.WrappedObj = 5;
ProtoBuf.Serializer.NonGeneric.Serialize(ms, srariazeObj);
Type is not serializable via protobuf-net, and neither is object. I understand what you are trying to do, and if you honestly cannot know the types in advance. I suspect you should consider serialising the AssemblyQualifiedName of the type (a string) and a byte[] for the object (via MemoryStream). I can whip up an example later if you like (let me know).
However, if it is possible to state a finite lost of types you need to support (for example "string or int or Customer or Guid only") then there is a much more efficient and convenient approach - again I can whip up an example if this is your scenario - let me know.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With