4

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

Specifically I'm just trying to serialize/deserialize the base Exception class and all other exception classes that inherit from it. Will I have to create a new RunTypeModel that specifies every possible exception class that I will ever need to serialize, or can I somehow tell Protobuf-Net to serialize them all the same way without listing every single one?

Any help is very appreciated since I am brand new to Protobuf-Net and I'm still trying to understand it all.

2 Answers 2

4

protobuf-net is designed to serialize DTO models, but not exceptions - very similar to XmlSerializer etc (but binary rather than xml, obviously). Serialising exceptions is not currently built in. It may be possible to hack some things, but this isn't really a designed feature.

Sign up to request clarification or add additional context in comments.

2 Comments

I ultimately solved this problem by creating an ExceptionProxy class that uses a little ugly reflection to extract the data from an exception and serialize it. I then re-hydrate the exception graph on the other side using the deserialized ExceptionProxy class information and more reflection. It isn't pretty, but it works quite well.
You can bypass this issue by serializing the Exception as a byte array and then deserialize it in the client side
0

You really can´t serialize a class like

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

But doing a small change will be possible to serialize

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

This was the only way that I found to serialize an exception.

1 Comment

Tried, this didn't seem to work for me. This worked: stackoverflow.com/questions/94488/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.