If someone else comes across this same exception, with the same behavior of debugging to the end in the server, but getting the exception on the return to the client, another possible cause is an uninitialized enum in the return data contract where the enum has explicit values, but no explicit zero value.
[ServiceContract]
public interfact IMyService
{
[OperationContract]
MyResult DoSomething();
}
[DataContract]
public class MyResult
{
[DataMember]
public OperationStatus Status {get; set;}
[DataMember]
public string ErrorText {get; set;}
}
[DataContract]
public enum Operation Status
{
[EnumMember]
Success = 1,
[EnumMember]
Failure = 2
}
public class MyService : IMyService
{
public MyResult DoSomething()
{
var result = new MyResult();
// ... do work, but don't set any properties on result ...
return result;
}
}
The reason the error happens in this scenario is that result.Status defaults to zero, but the data contract does not provide any means to serialize it, since it is not one of the explicitly defined enum values.
The solution (assuming you really do need this enum with explicit integer values) is to either set the enum value in the return object, or provide a default (zero) value.
[DataContract]
public enum Operation Status
{
[EnumMember]
Unknown = 0,
[EnumMember]
Success = 1,
[EnumMember]
Failure = 2
}
--Bill