Question

I have a DTO as below -

[Serializable()]
Public Class DTO
{
Public Exception ex {get;set;}
}

When i pass the object of type DTO from RIA service, on client side I do not see the property ex. Please help me with this proble.

Était-ce utile?

La solution

As a sidenote, I do not think of Exceptions should be send directly between clients/ server. Instead I recommend catching them at an appropriate point and re-format the exception information into something more generic before sending it to the receiving side.

As for your actual problem, you might have hit restrictions of the [Serializable] functionality. In MSDN article Serialization in Windows Communication Foundation it says (highlights by me):

The default mapping for [Serializable] is different from the one used with XmlSerializer. Here, all fields are included in the mapping, whether public or private, and properties are never included.

You might implement your own custom error class that supports serializing.

See SO thread How to serialize an Exception object in C#? for an example.

[EDIT]

If that is too much effort, as a quick win, you could try to change the class definition into:

[DataContract]
public Class DTO
{
    [DataMember]
    public Exception ex {get;set;}
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top