Visual Studio and .NET Framework Home
ObsoleteAttribute on abstract properties doesn't always make the compiler flag usage with a warning
Lasse V. Karlsen
2/23/2009 2:35:30 AM
User(s) can reproduce this bug
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.
Visual Studio 2008 SP1
Windows XP Professional
Operating System Language
Steps to Reproduce
Compile the attached source code, no need to run it.
Check the warning list, it flags lines 62, 63 and 65 as using an obsoleted property.
Line 62, 63, 64 and 65 should be flagged. Note 64.
TAP Code (if applicable)
You can indicate your satisfaction with how Microsoft handled this issue by completing this quick
3 question survey
to post a comment.
Please enter a comment.
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" :)
C# Compiler SDE
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.
Visual Studio Product Team
to post a workaround.
Please enter a workaround.
© 2014 Microsoft