ObsoleteAttribute on abstract properties doesn't always make the compiler flag usage with a warning - by Lasse V. Karlsen

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 417159 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 2/23/2009 2:35:30 AM
Access Restriction Public


If I flag a property of a class as Obsolete, and then access that property, the access is flagged with a warning.

However, if I in the code that accesses the property just move on to sub-properties of the returned object, the compiler doesn't complain.

Attached is example source code. There's four lines near the bottom, marked #1-#4. I'd expect all of them to be flagged as using an obsoleted property. #3 isn't, however. Note that it accesses the same property that #4 does, which is flagged with a warning, but #3 moves on to read the .Count property of the object returned, whereas #4 simply gets the collection object.

Edit: After getting some answers on StackOverflow.com I'm posting the link to that question here: http://stackoverflow.com/questions/577132/why-are-c-collection-properties-not-flagged-as-obsolete-when-calling-properties

In particular, note Jon's and Marc's comments about both mono and the .NET 2.0 compiler getting it right, but the 3.5 doesn't. There's also a shorter code-example there from Marc.
Sign in to post a comment.
Posted by Microsoft on 3/16/2009 at 7:22 PM
Thanks for reporting this Lasse. This has been reported a couple times before already (see customer feedback IDs 366851 and 368587) and has been fixed already in the C# 4.0 compiler. Unfortunately there are no plans to release a fix for the NDP 3.5 compiler and there is no work around I know of.

I have posted an answer on stackoverflow explaining this bug. Thanks for adding a question to stackoverflow, it comes up on the front page of google if you search "C# properties obsolete" :)

Ian Halliday
C# Compiler SDE
Posted by Microsoft on 2/24/2009 at 2:10 AM
Thanks for your feedback. We are escalating this bug to the product unit who works on that specific feature area. The team will review this issue and make a decision on whether they will fix it or not for the next release.

Thank you,
Visual Studio Product Team