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

rwandering.net

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.
Argh.

Tags: ,

    Trackback

3 Comments »