Monday, 18 June 2007

Windows Communication Foundation Deserialization Bug

I recently had a bash at putting a WCF service together. I did all the tutorials and everything seemed ok so i had a bash at my own. Well i put it all together but could i get to consume it in a windows application??? Could i b*&^*^*.

I was at it ages until i finally discovered why! I am using VB.net for this implementation. All the demos and tutorials i did in c# which is fine but for my project it had to be in vb.net. It turns out there is a compilation switch that is different in VB.net and this causes a namespace problem which totally fricks up the deserialization of complex types! Working with strings and ints - no problem. Basic complex type such as a person with firstname and surname - forget it. All i got was an empty instance.

I wont go into the number of things i tried to get it all working but put it this way - i learnt a hell of a lot about xobjectgen and serialization.

So here is the fix! All you have to do is clear out the root namespace in your windows application and VOILA! It works.

If you are using C# you will not hit this problem because of the compiler switch you dont see.

I hope this saves someone a weeks worth of work pulling their hair out because i did! I was on the verge of binning WCF altogether. Now i think its pretty neat! And it seems very quick with the new high speed serialization engine.

No comments: