How to serialize .Net exceptions using Protobuf-Net?

Can someone give me an example or point me to a resource on how to use Protobuf-Net to serialize / deserialize some bulit-in system classes?

In particular, I'm just trying to serialize / deserialize the base Exception class and all other exception classes that inherit it. Should I create a new RunTypeModel that sets up all the possible exception classes that I will ever need for serialization, or can I somehow tell Protobuf-Net to serialize them the same way without listing any of them?

Any help is greatly appreciated since I'm new to Protobuf-Net and I'm still trying to figure it all out.

+3
source share
2 answers

protobuf-net is designed to serialize DTO models, but not exceptions - very similar to XmlSerializer, etc. (but binary, not xml, obviously). Serial exceptions are not currently built-in. Some of them may be hacked, but this is not a specially designed function.

+3
source

You really can't serialize a class like

public class MyTest
{
    [ProtoMember(1)]
    public Exception MyException { get; set; }
}

But a small change will be possible for serialization.

public class MyTest
{
    [ProtoMember(1, DynamicType = true)]
    public Object MyException { get; set; }
}

This was the only way I found exception serialization.

0
source

All Articles