Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 138329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:14:49+00:00 2026-05-11T07:14:49+00:00

I tried to flag a collection property on a class as Obsolete to find

  • 0

I tried to flag a collection property on a class as Obsolete to find all the occurances and keep a shrinking list of things to fix in my warning-list, due to the fact that we need to replace this collection property with something else.


Edit: I’ve submitted this through Microsoft Connect, issue #417159.

Edit 16.11.2010: Verified that this now works in the C# 4.0 compiler, both when compiling for .NET 3.5 and 4.0. I get 4 warnings in the posted code, including the one with the comment ‘Not OK?’.


However, to my surprise, the list only contained a few occurances, far fewer than I knew there were, and spotchecks tells me that for some reason, the usage of the property isn’t always flagged as obsolete by the compiler in the warning list.

Here’s an example program, ready to compile in Visual Studio 2008.

Note the four lines near the end tagged with #1-#4, of these, I’d expect all of them to report that the property used was obsolete, but #3 isn’t, and it seems that if I just move on to the collection properties or methods directly, the usage of the property itself isn’t flagged as obsolete. Note that #3 and #4 is referencing the same property, and #4 is flagged as using an obsolete property, whereas #3 isn’t. Tests shows that if, in the expression, I access properties or methods of the collection the property returns, the compiler doesn’t complain.

Is this a bug, or is this a ‘hidden gem’ of the C# compiler I wasn’t aware of?

using System; using System.Collections.Generic;  namespace TestApp {     public abstract class BaseClass     {         [Obsolete]         public abstract String Value         {             get;         }          [Obsolete]         public abstract String[] ValueArray         {             get;         }          [Obsolete]         public abstract List<String> ValueList         {             get;         }     }      public class DerivedClass : BaseClass     {         [Obsolete]         public override String Value         {             get             {                 return 'Test';             }         }          [Obsolete]         public override String[] ValueArray         {             get             {                 return new[] { 'A', 'B' };             }         }          [Obsolete]         public override List<String> ValueList         {             get             {                 return new List<String>(new[] { 'A', 'B' });             }         }     }      public class Program     {         public static void Main(String[] args)         {             BaseClass bc = new DerivedClass();             Console.Out.WriteLine(bc.Value);             // #1 - OK             Console.Out.WriteLine(bc.ValueArray.Length); // #2 - OK             Console.Out.WriteLine(bc.ValueList.Count);   // #3 - Not OK?             List<String> list = bc.ValueList;            // #4 - OK         }     } } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:14:49+00:00Added an answer on May 11, 2026 at 7:14 am

    Hmm… looks like a compiler bug to me! It fails the following (ECMA 334v4):

    24.4.3 The Obsolete attribute The attribute Obsolete is used to mark types and members of types that should no longer be used. If a program uses a type or member that is decorated with the Obsolete attribute, then the compiler shall issue a warning or error in order to alert the developer, so the offending code can be fixed. Specifically, the compiler shall issue a warning if no error parameter is provided, or if the error parameter is provided and has the value false. The compiler shall issue a compile-time error if the error parameter is specified and has the value true.

    In particular, when marked true it should issue an error, and it doesn’t. Good find! You could report it on ‘connect’, or if you don’t want the pain of setting up a login, let me know and I’ll happily log it (referencing your post here; no attempt to ‘steal’ anything).

    (update)

    Reduced code to reproduce:

    using System; using System.Collections.Generic; static class Program {     static void Main() {         int count = Test.Count;     }      [Obsolete('Should error', true)]     public static List<string> Test {         get {throw new NotImplementedException();}     } } 

    Note that mono 2.0 gets it right, as does the MS C# 2.0 compiler. It is only the MS C# 3.0 (.NET 3.5) compiler that is broken.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 74k
  • Answers 74k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer If you want to monitor the audio session stuff, you… May 11, 2026 at 2:13 pm
  • added an answer You can only place stylesheet links in the header of… May 11, 2026 at 2:13 pm
  • added an answer I'm not sure if there are any plugins out there… May 11, 2026 at 2:13 pm

Related Questions

I tried to install Delphi 7 on Vista several times and Vista prevented me
I tried to package a Twisted program with py2exe, but once I run the
I tried to set innerHTML on an element in firefox and it worked fine,
I tried to use DriveInfo.IsReady, but it returns false if an unformatted floppy is
I tried to override the settings in the default stlyesheet that comes with the
I am working on a background program that will be running for a long
I need to unzip a compressed file on the fly in my program. It
I want to turn off PHP's magic quotes. I don't have access to php.ini.
I'm currently working on a parser for our internal log files (generated by log4php,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.