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

  • SEARCH
  • Home
  • 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 691997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T02:36:16+00:00 2026-05-14T02:36:16+00:00

I’ve just started to work with FxCop to see how poorly my code does

  • 0

I’ve just started to work with FxCop to see how poorly my code does against its full set of rules. I’m starting off with the “Breaking” rules, and the first one I came across was CA2227, which basically says that you should make a collection property’s setter readonly, so that you can’t accidentally change the collection data.

Since I’m using MVVM, I’ve found it very convenient to use an ObservableCollection with get/set properties because it makes my GUI updates easy and concise in the code-behind. However, I can also see what FxCop is complaining about.

Another situation that I just ran into is with WF, where I need to set the parameters when creating the workflow, and I’d hate to have to write a wrapper class around the collection I’m using just to avoid this particular error message.

For example, here’s a sample runtime error message that I get when I make properties readonly:

The activity 'MyWorkflow' has no public writable property named 'MyCollectionOfStuff'

What are you opinions on this? I could either ignore this particular error, but that’s probably not good because I could conceivably violate this rule elsewhere in the code where MVVM doesn’t apply (model only code, for example). I think I could also change it from a property to a class with methods to manipulate the underlying collection, and then raise the necessary notification from the setter method. I’m a little confused… can anyone shed some light on this?

  • 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. Editorial Team
    Editorial Team
    2026-05-14T02:36:16+00:00Added an answer on May 14, 2026 at 2:36 am

    What this specific rule tells is that a collection property should be made read-only because you don’t need to assign a whole collection to a property.

    For instance, imagine a class like this:

    public class Foo
    {
       public ObservableCollection<int> Bar { get; set; }
    }
    

    What would happen if somewhere in the code I have the following line:

    var f = new Foo();
    f.Bar = new ObservableCollection<int>();
    f.Bar.AddRange(new int[] { 1, 2, 3, 4 });
    // ...
    // Attaches and handlers to the collection events
    // ...
    f.Bar = new ObservableCollection<int>();
    f.Bar.AddRange(new int[] { 5, 6, 7, 8 });
    

    When the last two lines of code are executed the attached event handlers would not be fired, because the Bar property has a complete different object.

    On the other hand, if the property were read-only the events would be fired and everything would behave as expected.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer class rand_number { //... if(rand_n == 2) { boolean guessed… May 16, 2026 at 3:58 pm
  • Editorial Team
    Editorial Team added an answer Here is the most elegant (yet somewhat hackish) way I… May 16, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer it can't be done by float, because it's no valid… May 16, 2026 at 3:57 pm

Trending Tags

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

Top Members

Related Questions

I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a JSP page retrieving data and when single or double quotes are
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,

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.