0
votes

I have a WCF service I use to submit bugs for my project. Snippet of the data class:

Private _exception As Exception
<DataMember()> _
 Public Property Exception As Exception
    Get
        Return _exception
    End Get
    Set(ByVal value As Exception)
        _exception = value
    End Set
End Property

I have a Silverlight app that uses the WCF service to send any bugs home if and when they occur. This is the error I'm testing with:

 Dim i As Integer = 5
 i = i / 0

The problem is SL is banging on with this message:

System.ServiceModel.CommunicationException was unhandled by user code Message=There was an error while trying to serialize parameter :bug. The InnerException message was 'Type 'System.OverflowException' with data contract name 'OverflowException:http://schemas.datacontract.org/2004/07/System' is not expected. Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.

Is there some trick to get a generic .NET Exception (any InnerException) to serialize properly? I'm not doing anything funky with the exception - it's just a plain 'ol exception

Thanks for any help.

2

2 Answers

1
votes

I doubt very much that you can serialize a .NET-specific type like an Exception. I recommend you create your own class to hold the parts of the exception you want serialized.

0
votes

This may be a problem with implicitly casting the OverflowException into a System.Exception.

The data contract serializer is very specific. This can be good and bad.

I would try just throwing a new System.Exception to see if this works OK.

If this is the case, you may need to dumb down the exception, creating a new System.Exception with the original exception message in it.

Or, like John said, you might have a better go of it if you create a custom error class that holds the exception info.