Tags: , , | Categories: Code Development, Testing Posted by nurih on 10/23/2008 10:08 AM | Comments (38)

You may be surprised to find that classes are serialized by WCF without any [DataContract] attribute attached to them. I certainly was!

When WCF came out, there was much fanfare of the new, improved, superior WCF serializer (justified IMHO). The main policy sizzle was that unlike the [Serializable] marking a POCO object and then [NonSerialized] attribute marking specific fields (opt-out), WCF will now use "opt-in": Only properties specifically decorated will be serialized.

This serialization policy was clearly expressed, and the side effect of it all is that suddenly I have a bunch of projects that fail some unit tests. Upon digging, I found that SP1 has introduced a new kink: if you don't decorate your class at all (omit / not add the [DataContract] attribute) then the object becomes "fully" serializable by WCF. All public properties will be automatically included.

This may seem as a huge step back to those that relied on the opt-in feature to hide certain classes from the serializer. This also may be a huge sigh of relief to those who cringed at the effort of (re)decorating all their message and value objects for WCF.

Note that now with SP1, if you do decorate an object with [DataContract] then the old rules apply – only properties with [DataMember] will be serialized. So to be selective, you may still decorate with [DataContract] and then selectively decorate only the properties you want.

I don't know what led to the exact decision, and the syntax nuance definitely walks a fine line. One could argue that classes without decoration now serialize without effort, but ones marked for WCF specifically still behave as previously advertised.

All in all, 2 hours of head scratching in disbelief, 1 hour to change some unit test expectations, not too awful. Long live refactoring tools in Visual Studio!

Comments (38) -

bad credit loans United States on 9/30/2009 10:43 AM Hi there, I found your blog via Google while searching for first aid for a heart attack and your post looks very interesting for me.
MrBarns United States on 2/5/2010 5:58 PM There's good info here. I did a search on the topic and found most people will agree with your blog. Keep up the good work mate!
cash advance United States on 2/7/2010 11:05 PM Never underestimate the power of passion.
Tyson F. Gautreaux United Kingdom on 3/12/2010 11:53 PM Well, your website is actually the greatest on this worthy topic. I concur with you and will eagerly look forward to your incoming updates.
Issac Maezer United Kingdom on 3/13/2010 6:04 AM I will right away grab your rss feed to stay privy of any updates. Gratifying work!
Hide Away Bed on 3/17/2010 10:42 PM Do Airsprung Beds offer a guarantee? In the unlikely event of a defect in material or workmanship Airsprung Beds offer a 1 year guarantee and up to a 10 year warranty. The Comfortably Firm, Gently Supportive, & Memory Master collections all offer 1 year guarantee and a 10 year warranty. The children’s collection, Bright Young Things, and the mattress collection have a 1 year guarantee and a 7 year warranty. http://www.murphybedssale.com.
Guenstiges Tagesgeldkono on 3/18/2010 3:58 PM I hope that it might give an easier way for it ...
Samantha Brian on 3/19/2010 2:27 AM I like the blog, but could not find how to subscribe to receive the updates by email. Can you please let me know?
real estate training on 3/19/2010 5:13 PM Thanks for taking the time to share your thought. If more of us used your line of thinking, the world would be a better place.
round rug on 3/19/2010 5:57 PM Well, this is my first visit to your blog! We are a group of volunteers and starting a new initiative in a community in the same niche. Your blog provided us valuable information to work on. You have done a marvellous job!
Bulgarian Property on 3/19/2010 10:01 PM I like the blog, but could not find how to subscribe to receive the updates by email.
Voyage Bangkok on 3/25/2010 3:06 AM Hi there! I take pleasure in looking through your posts every single morning. It’s obvious that your thoughts reflect a lot of other people’s opinions too.
Marry Mosen on 3/25/2010 6:54 AM Hi, i just thought i'd post and let you know your blogs layout is really out of window on the K-Melon browser. But anyway, tnx for the great information
Rait Raak,
<A href="www.articlesbase.com/.../jamorama-acoustic-guitar-scam-1878889.html">Jamorama Acoustic Guitar</A>
Vertie Lotz on 3/27/2010 11:12 AM The Kentucky Wildcats are currently ranked second.
Rugby News on 3/27/2010 11:39 AM Nice to know!
<A href="http://www.betscore.org/live-tv">Live TV</A> &amp; <A href="www.betscore.org/basketball">Basketball news</A>
NBA News on 3/27/2010 11:41 AM Nice to know...
<A href="http://www.betscore.org/bet-tips">Bet tips</A> &amp; <A href="http://www.betscore.org/baseball">Baseball News</A>
bondage United States on 3/28/2010 4:26 AM You have a really great design for your bondage blog. Did you design it yourself or did you get someone to do it?
Altersvorsorge on 3/28/2010 6:28 AM A few days ago I discussed that topic with another guy just with a different result. It s a topic challenging for discussions again and again. Nice issues you used for argumentation
bondage United States on 3/28/2010 9:48 AM I don't agree with everything in this blog, but you do make some very good points. Im very interested in this matter and I myself do alot of research as well. Either way it was a well thoughtout and nice read so I figured I would leave you a bondage comment. Feel free to check out my website sometime and let me know what you think.
Annmarie Zepf on 3/28/2010 12:49 PM Hi, I really admire the look of your site. What design are you using?
bondage United States on 3/28/2010 3:49 PM It appears that you've put a good amount of effort into your bondage article and I demand a lot more of these on the World Wide Web these days. I truly got a kick out of your post. I do not have a bunch to to say in reply, I only wanted to register to say phenomenal work.
Ike Paton on 3/29/2010 5:02 AM A miracle anti-wrinkles system. You can do it too. Learn more here: <a href="http://elizasmakeover.com/">http://elizasmakeover.com/</a>
Rob on 3/29/2010 7:37 AM I really appreciate what you post here, very insightful and smart. One problem though, I'm running Firefox on Ubuntu and some of your layout pieces are a little misaligned. I know it's not a common setup, but it's still something to to keep in mind. Just giving you a heads up.
Mariusz Pudzianowski VS Yusuke Kawaguchi on 3/29/2010 7:40 AM I want to make my first blog, do you thing that blogenginenet cms is good ?
PS3 Magic United States on 3/29/2010 10:15 AM Hey i found your article on google, just wrote it, great post, keep the good work.
PS3 Magic United States on 3/29/2010 10:42 AM Good job on this article, found it on google, keep up the good work.
PS3 Magic United States on 3/29/2010 3:02 PM hey great article, pleasure for reading. Keep the good work.
make profits on betting on 3/30/2010 12:13 AM Excellent post i am sure that i will come back here soon
Health Article Directory Submission on 3/30/2010 1:30 AM Can you move your link directory or rename it? Yes, at any time. But you must update your profile with your link partners by logging into your partners sites. If their servers can't find your link back to them on the directory page that they have on their records they will automatically exclude your site from their link directory. http://www.all-health-dir.com.
Chapel Hill Houses for Sale United States on 3/30/2010 6:04 AM Hope you haven't copy pasted this from somewhere else. Nice post.
buying domain names Singapore on 3/30/2010 1:17 PM Great post I must say.. Simple but yet entertaining and engaging.. Keep up the good work!
Nissan on 3/30/2010 4:48 PM Oh my i hope you have a great day! I think I have more useful points on using Twitter to market your blog +N Consulting Inc. | WCF Serialization – new in .NET framework 3.5 sp1. A speedy black wolf jumped over the lazy hound. Do you now any free website with manuals in pdf's? Nissan Send me news to Kuhl@yahoo.com
Felton Peshek Poland on 7/6/2010 10:54 AM I thought it was going to be some boring old site, but I'm glad I visited. I will post a link to this site on my blog. I am sure my visitors will find that very useful.
murano chandeliers United States on 7/7/2010 12:36 AM This is a great blog. I just thought I'd mention it.
SEO for Wordpress United States on 7/7/2010 3:16 PM thecraze6man8@yahoo.com
rolex replica United States on 7/7/2010 10:35 PM Thanks for your visiting this www.watchau.com online store.
table magician United States on 7/8/2010 11:29 AM Come on guys, let's keep it clean. This is a good blog. Good info mate.
watching movies online United States on 7/9/2010 5:53 PM Hello, Interesting blog you have here and thanks for the info sharing. I've searched a lot for this,1 vote from me Smile I wish i could organize things like you do on your blog Smile
Comments are closed