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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T00:19:26+00:00 2026-05-16T00:19:26+00:00

I am trying to track down a very elusive bug in an application that

  • 0

I am trying to track down a very elusive bug in an application that manipulates a FlowDocument. I have shown below three consecutive lines of debugging code, together with their output:

Debug.Assert(ReferenceEquals(document1, document2));
Debug.WriteLine(document1.Blocks.Count); // 1
Debug.WriteLine(document2.Blocks.Count); // 3

Can anyone help me to understand how two references to the same object can have different values for a given property? Or am I missing something about the way ReferenceEquals works?

Thanks,

Tim

Edit:

If I change the assertion to an if block, the debugging code never runs …

if (ReferenceEquals(document1, document2))
{
    Debug.WriteLine(document1.Blocks.Count);
    Debug.WriteLine(document2.Blocks.Count);
}

… which makes me feel utterly stupid, because the ReferenceEquals test is clearly working, but I don’t understand why the assertion is not working.

  • 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-16T00:19:26+00:00Added an answer on May 16, 2026 at 12:19 am

    Possibilities (some of which you have already discounted in the comments):

    1. Some external process, say something that is loading Blocks into FlowDocument, is altering the value between writes.

    2. Heisenberg: reading the Blocks property affects it. This happens sometimes when reading rows from a data source. I’m not familiar with FlowDocument so I’m not sure how feasible this is.

    3. If the instances were declared as different types, their references would still be equal, but the value of Blocks (or Blocks.Count) could be overridden, resulting in different return values since different code might be called – like Object.ToString() vs Int.ToString().

    4. You’re somehow calling this debug code in the middle of a loop. This could happen if you’re running it in the command window or some attached debugger instead of within the application.

    5. You have dead pixels on your screen that make the first “3” look like a “1”.

    6. You live next to a nuclear reactor.

    Some things to try:

    1. Run your .Assert code in a loop and see if the values stabilize.

    2. Set a read/write breakpoint on the Blocks value. (I know you can do this in C, but haven’t tried it in C#)

    Update

    Regarding your additional question about .Assert() not working as expected:

    Just looked at this note on MSDN regarding Debug.Assert().

    By default, the Debug.Assert method works only in debug builds. Use the Trace.Assert method if you want to do assertions in release builds. For more information, see Assertions in Managed Code.

    Are you running a debug build or a release build?

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

Sidebar

Related Questions

I am trying to track down what appears to be a very strange bug.
Trying to track down a bug in an application, but need to confirm whether
So I have a nasty stack overflow I have been trying to track down
I am trying to track down a very odd crash. What is so odd
This is a problem I have been trying to track down for a couple
I'm trying to track down an issue in our system and the following code
We're trying to track down some .Net assembly dependency problems. On Windows XP, does
I'm trying to track down a memory leak and I think it has to
I'm trying to track down a memory leak in a java process, using jmap
I'm trying to do something to track down the problem, but there's not much

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.