Search code examples
c#.netvisual-studiodebuggingbreakpoints

How do I set a breakpoint on every access to a class


When working with third party systems, especially very configurable systems that dynamically load providers, controllers, components and so on, I sometimes just want to know when a certain object or class is accessed. Normally, I'd place a breakpoint on any potential lines in my source (a nuisance, but it works), but if source is not available:

How can I instruct Visual Studio 2010 Ultimate to break on any and each access to a given class?

Note: as far as my experience goes, this is not generally possible, but I'd like to see it confirmed


Solution

  • You can click Debug > New Breakpoint > Breakpoint at Function. Ctrl-B brings you there directly. It'll allow you to break at a specific function.

    During debugging, you can see in the Breakpoints-window whether the method is found and will be hit (red round icon) or not (white with circle icon, as of disabled breakpoint), just as with normal breakpoints.