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 607509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:22:03+00:00 2026-05-13T17:22:03+00:00

I have been trying to wrap my head around this FXCop violation DoNotDeclareReadOnlyMutableReferenceTypes MSDN:

  • 0

I have been trying to wrap my head around this FXCop violation “DoNotDeclareReadOnlyMutableReferenceTypes”

MSDN: http://msdn.microsoft.com/en-us/library/ms182302%28VS.80%29.aspx

Code from MSDN which would cause this violation:

namespace SecurityLibrary
{
    public class MutableReferenceTypes
    {
        static protected readonly StringBuilder SomeStringBuilder;

        static MutableReferenceTypes()
        {
            SomeStringBuilder = new StringBuilder();
        }
    }
}

From Jon’s answer here and here , I understand that the field holding the reference to the object (in this case SomeStringBuilder) is readonly and not the object itself (which is created by new StringBuilder() )

So taking this example, how would I change the object itself, once the field has a reference to it ? I like Eric Lippert’s example of how the readonly array can be changed, and would like to see something similar for any other mutable reference type

  • 1 1 Answer
  • 2 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-13T17:22:03+00:00Added an answer on May 13, 2026 at 5:22 pm

    As the MutableReferenceTypes class is presented in the question, you can’t really mutate it from any outside caller since the SomeStringBuilder field is private.

    However, the class itself could mutate the field. It doesn’t currently, but it could in a later iteration.

    Here’s an example method:

    public static void Mutate()
    {
        SomeStringBuilder.AppendLine("Foo");
    }
    

    Calling the Mutate method will mutate the class because SomeStringBuilder will now have changed.

    Immutability is not only about the current incarnation of your code, but also about protecting yourself from future mistakes. Not that all classes need to be immutable, but it’s safest to stay consistent if you elect to create an immutable type.

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

Sidebar

Related Questions

Ok, I have been trying to wrap my head around this http live streaming.
I have been trying to wrap my head around this issue for the past
I have been trying to wrap my head around this for a while now
I have been trying to wrap my head around why this is happening but
I have been trying to wrap my head around this issue but I am
I have been trying to wrap my head around the concept of semaphores in
Good evening, I have been trying to wrap my head about this, below, code
I've been trying to wrap my head around this concept and how to route
For sometime now, I have been trying to wrap my head around the reason
I've been struggling to wrap my head around this for some reason. I have

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.