I am currently debugging my application. (.Net Framework 4.6.2) I have an instance of a class, that is somehow getting modified when performing a specific function (on debugging). I would now like to understand, what accessed and changed the object.

 void PerformCalculationWithObject(MyClass obj)
 {
      DoSomething(obj); // calls a lot of different operations
                        // which sometimes modify obj, and sometimes not.
 }

But the class is large and complex, and many function are called underneath the function.

I am aware that my biggest issue is the lack of good object-design in this legacy code, which leads to this problem.

So the question is, if there is a possibility to auto-break, when some member of the class (maybe even just fron specific instance) is called (without putting plenty of break-points).

2 Answers

0
Shameer A Mohammed On

Something I usually do in such cases is change the class member varibles which I suspect to change to properties with a get and set method and then put a breakpoint int the set method.

1
Andy Sterland On

If you're using VS 2019 and .NET Core 3.0 there are data breakpoints that can be set on an object from the watch window. Just right click on an expression in the watch window (in this case add a watch for obj) and then choose "Break when value changes".

More info on this is over at: https://devblogs.microsoft.com/visualstudio/break-when-value-changes-data-breakpoints-for-net-core-in-visual-studio-2019/

I appreciate this might not help you as you're debugging a legacy application but perhaps either it can run .NET Core 3 while debugging or some other user will find this answer useful.