Wednesday, May 1, 2013

C# code to force the debugger to launch

There are times where you just can’t manually attach the Visual Studio debugger to your code. Like when you’re trying to debug Sharepoint feature events (FeatureActivated, FeatureDeactivating, etc.) when Visual Studio is deploying your SharePoint project.

For those situations you can use this line of code to attach Visual Studio to your process.

System.Diagnostics.Debugger.Launch();

image

image

Just make sure to remove it before you ship your software.

3 comments:

  1. Nice tip Justin. I've had hit or miss issues trying to debug certain things like that. Thanks!

    ReplyDelete
    Replies
    1. Happy to help Dan. When all else fails, I drop to that old stand by.

      Delete
  2. it takes too long time :(

    ReplyDelete