Serializing exceptions

C

Chris Fellows

I have an ASP.NET 2 web service that needs to return a serialized exception
from its methods so that the caller can take specific actions for certain
exceptions.

I've tried XML serialization, SoapFormatter & BinaryFormatter but I cannot
get any of these methods to work. XML serialisation throws an exception on
serialization due to not being able to serialize Dictionary objects.
SoapFormatter throws an exception 'Root node missing...' on deserialization
and BinaryFormatter throws an exception 'End of Stream...' on
deserialization. From looking at newsgroup postings then these seem to be
common problems but I haven't seen any with a solution that works.

I've tried using MemoryStream & FileStream classes to do the
serialization/deserialization but none work. I'm storing the serialized data
in a byte array and I'm dimensioning the array to the length of the stream.
The stream that deserializes the data shows the correct length prior to
calling the formatter's Deserialize method. When the Deserialize method is
called then the return value is being cast to the correct exception type.

I experience the same problems even if the web service tries to deserialize
the data as soon as it has serialized the data. (i.e. After the exception is
serialized into the stream then it calls the Deserialize method of the class
instance that the exception was serialized into.)

Can someone help me out with some C# 2.0 code that can serialize and
deserialize an exception?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top