There is a technique that you can use to inject code from within a breakpoint. It's easy, and it works.
- Set a breakpoint
- Right-click on the breakpoint, and choose "conditions"
- Put your line of code in the condition (it does not have to return a bool)
- Run
When your breakpoint is hit, the code will execute, and the debugger will NOT stop on the breakpoint (because you didn't return a bool).
I got this tip from the Visual Studio tips blog:
http://blogs.msdn.com/b/zainnab/archive/2010/05/04/set-a-complex-breakpoint-condition-vstipdebug0022.aspx
Here's an example program that illustrates the technique:
static void Main(string[] args)
{
List l = new List();
Console.WriteLine(l[0]);
System.Console.ReadLine();
}
If you run this code as-is, you will get an exception. However, before yourun it, add a breakpoint to hte Console.WriteLine() line.
Right-click on the breakpoint, and choose "conditions"
In the condition dialog, add the following code:
l.Add("hello")
Now run.
Clearly, a person could get into a lot of trouble with this "feature" -- you can change the behavior of your application with breakpoints such that an independent build of the code behaves differently from when it is run on your machine in your debugger. So, be very careful...