Sunday 31 May 2009

Duplicate types generated in WCF proxy

The other day I ran into a problem where I was generating a WCF proxy which without any modification was not compiling. The error message was that some class "C" with property "P" was already defined.

When verifying the generated proxy I noticed that I indeed has 2 versions of a fault contract in my proxy code:
- one decorated with the DataContractSerializer
- and the other one was present to be used by the XmlSerializer

I was getting this problem because I was using a fault contract shared by 2 service operations. The return type of one these operations was of type "Stream". Apparently the "Stream" class is not compliant with the DataContractSerializer and that is why WCF was generating XmlSerializable faut contract. And as my second service operation was DataContractSerializable, WCF was generating a another version of my fault contract which was DataContractSerializable.