I wish to set a breakpoint on the System.Threading.SynchronizationContext::SetSynchronizationContext static method so I can find out when the synchronization context is being set.
However I can’t find how to set a breakpoint in a method I don’t have the source code to.
(This should be easy!, but when I try to set the breakpoint on a method from the breakpoints window it does recognise the method.)
You can set a breakpoint at a line number, using the stop at command, where n is a source code line number and filename is an optional program file name qualifier. If the line specified is not an executable line of source code, dbx sets the breakpoint at the next executable line.
To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint. The breakpoint appears as a red dot in the left margin.
Press F3 and then press F9 to add a breakpoint.
Breakpoints are set with the break command (abbreviated b ). The debugger convenience variable `$bpnum' records the number of the breakpoint you've set most recently; see section Convenience variables, for a discussion of what you can do with convenience variables.
Click Debug, Windows, Breakpoints, click New, Break at function, enter System.Threading.SynchronizationContext.SetSynchronizationContext
, and click OK.
It will give you a warning, which you should ignore. I tried it, and it does work.
Edit by Ian Ringrose
I also had to turn off the "Enable Just My Code" setting in the Debugging configuration.
Start Visual Studio 2008 and bring up Tools > Options > Debugging > General. If you are running under the Visual Basic Profile, you will need to check the box on the lower left of the Options Dialog marked "Show All Settings" before continuing (other profiles won't have this option). Set the following settings: Turn OFF the "Enable Just My Code" setting
It is possible to debug the .NET framework classes. All you have to do, is setup VS.NET so that it is able to download the debug symbols for the .NET framework from one of Microsoft's servers.
You won't be able to set a breakpoint inside a .NET method though, but, you will be able to step into another method of the .NET framework, and while debugging, and once you've stepped into that method, (and VS.NET has opened the file that contains the SetSynchronizationContext method), you'll be able to set a breakpoint on that method.
For information on how to setup VS.NET so that you can debug the .NET framework, click here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With