Expert Texture Home Contact me About Subscribe Digipede Connect on LinkedIn rwandering on Twitter rwandering on FriendFeed

The blogged wandering of Robert W. Anderson

XmlSerializer should ignore ObsoleteAttribute . . .

. . . or respect the IsError property.

I found a problem in some code today. The class is a data-holder for XML serialization. One property has been deprecated and attributed with the ObsoleteAttribute to produce a compile-time warning for developers. Previous versions of the XML data must still be readable, but we want to make sure all of our code uses the correct property.

I assumed that on XML-deserialization, the property-setter would be respected; however, it is not.

This is wrong.

If a member is marked as obsolete with warning (i.e., deprecated) it should still be observed.  This is the case throughout .NET 2.0: deprecated members continue to function compatibly.
The only way that I can see the XmlSerializer observing this attribute is if IsError == true; however, even this is a stretch.  Really, this attribute should only impact compilation, not runtime.
Better yet, if a user wants a new version to exclude deserialization, we already have an attribute for that:  the XmlIgnoreAttribute.

Tags: ,



[…] Recently I complained about how the XmlSerializer treats the ObsoleteAttribute. […]

    Brian wrote @ September 25th, 2006 at 11:36 am

Yup. I just got burnt by this one in production myself. Do they even acknowledge the issue?

    Robert W. Anderson wrote @ September 25th, 2006 at 11:56 am

I don’t know if they have. As far as I know it is intended behavior. It sure ought to be documented, though.

Your comment

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>