debugging - Different property values on two references to the same object (C#) -
i trying track down elusive bug in application manipulates flowdocument
. have shown below 3 consecutive lines of debugging code, output:
debug.assert(referenceequals(document1, document2)); debug.writeline(document1.blocks.count); // 1 debug.writeline(document2.blocks.count); // 3
can me understand how 2 references same object can have different values given property? or missing way referenceequals
works?
thanks,
tim
edit:
if change assertion if
block, debugging code never runs ...
if (referenceequals(document1, document2)) { debug.writeline(document1.blocks.count); debug.writeline(document2.blocks.count); }
... makes me feel utterly stupid, because referenceequals
test working, don't understand why assertion not working.
possibilities (some of have discounted in comments):
some external process, loading blocks flowdocument, altering value between writes.
heisenberg: reading blocks property affects it. happens when reading rows data source. i'm not familiar
flowdocument
i'm not sure how feasible is.if instances declared different types, references still equal, value of blocks (or blocks.count) overridden, resulting in different return values since different code might called - object.tostring() vs int.tostring().
you're somehow calling debug code in middle of loop. happen if you're running in command window or attached debugger instead of within application.
you have dead pixels on screen make first "3" "1".
you live next nuclear reactor.
some things try:
run .assert code in loop , see if values stabilize.
set read/write breakpoint on blocks value. (i know can in c, haven't tried in c#)
update
regarding additional question .assert() not working expected:
just looked @ this note on msdn regarding debug.assert().
by default, debug.assert method works in debug builds. use trace.assert method if want assertions in release builds. more information, see assertions in managed code.
are running debug build or release build?
Comments
Post a Comment