Geeks With Blogs

News Opinions and articles on this blog are mine alone and do not represent my employer. All articles and blog entries are posted using a personal computer system outside of my employer network.
Sam Abraham Software Engineer/Architect: Putting Customers First

Most of us have probably used or know of the System.Diagnostics.Debugger.Break(). For more information on Debugger.Break checkout this link http://msdn.microsoft.com/en-us/library/system.diagnostics.debugger.break.aspx

Online documentation states that if no debugger is already attached, user would be prompted to attach one to executing program when the break is hit. For some reason however, this didn’t work for us when our desired breakpoint was in an OnInstall() function of an installer class.

Further digging revealed that the comments decorating the Break() call differ a bit from the online documentation:

// Summary:

// Signals a breakpoint to an attached debugger.

//

// Exceptions:

//   System.Security.SecurityException:

//     The System.Security.Permissions.UIPermission is not set to break into the

//     debugger.

[SecuritySafeCritical]

public static void Break();

 

Apparently, Break() only signals a breakpoint to an attached debugger as per the summary above.

In looking at other calls within the Debugger class, we found the Launch() function which is documented as following:

//
// Summary:
//     Launches and attaches a debugger to the process.
//
// Returns:
//     true if the startup is successful or if the debugger is already attached;
//     otherwise, false.
//
// Exceptions:
//   System.Security.SecurityException:
//     The System.Security.Permissions.UIPermission is not set to start the debugger.
[SecuritySafeCritical]
public static bool Launch();
 

This call forces the launch of debugger selection prompt where we can select Visual Studio 2010 as our JIT debugger. Once selected code execution breaks allowing us to step through the code. The Deubbger.Launch() call worked perfectly when called inside our OnInstall() function and allowed us to conveniently debug installer code.

Posted on Tuesday, May 24, 2011 11:24 AM Fladotnet.com , Tech Talk , VS2010 , .Net 4.0 | Back to top


Comments on this post: Debugging Install Functions in Visual Studio 2010

# re: Debugging Install Functions in Visual Studio 2010
Requesting Gravatar...
Odd. Break() has always worked for me within OnInstall. Thank you for the workaround if I run into this situation.
Left by Darius on May 24, 2011 2:22 PM

# re: Debugging Install Functions in Visual Studio 2010
Requesting Gravatar...
Break() worked fine for us in Visual Studio 2008/.Net 3.5. However, we ran into this issue for Visual Studio 2010/.Net 4.0.

Thanks for reading and sharing!
--Sam
Left by Sam Abraham on May 24, 2011 2:31 PM

Your comment:
 (will show your gravatar)


Copyright © Sam Abraham | Powered by: GeeksWithBlogs.net