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.

2 comments:

Anonymous said...

Thanks lot...how can i use the faultcontract for all operation and also avoid the duplicate proxy generation?

smmniceguy said...

So you are having a mix of DataContractSerializable and XmlSerializable types in your service contract. I don't think that is possible. What you could do is to move the operation contract which not is not DataContractSerializable in a separate service contract.