in

Dot Net Mafia

Group site for developer blogs dealing with (usually) .NET, SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, and other Microsoft products, as well as some discussion of general programming related concepts.

This Blog

Syndication

Archives

Corey Roth [MVP]

A SharePoint MVP bringing you the latest time saving tips for SharePoint 2013, SharePoint 2010, Office 365, SharePoint Online, MOSS 2007, ASP.NET, LINQ, and Visual Studio 2012.

Debugging a feature when using STSADM.EXE

Debugging a feature activation is relatively easy (even remotely), you simply attach to the w3wp.exe process that is running your particular SharePoint instance.  However, I have found that if you need to debug a feature that is activated with stsadm.exe, there is an extra step required.  The reason is that you need to not only attach to the w3wp.exe process but you also need to attach to stsadm.exe as well.  Of course, if you execute your stsadm command, then jump into Visual Studio and try to attach to the process, stsadm has probably already completed by the time you get there.  How do you get around this?  Well I can think of two ways.  One is cheesy but effective and one is a little more elegant. 

The Pause/Break Key

Yes, this old key from back in the DOS days (well probably earlier), can be your friend here.  First start out in Visual Studio and attach to the appropriate w3wp.exe process.  Next, go to your command prompt, run your feature activation command and quickly press the Pause/Break key.  The stsadm command will be paused.  Now, go back into Visual Studio and attach to the stsadm.exe process.  Once you are attached, go back to the command prompt and press any key and you will be good to go.  This is pretty cheesy as I said, but it does work pretty well.

System.Diagnostics.Debugger.Launch()

If you want a more elegant solution, you can launch the debugger via code in your feature receiver.  Simply, add the following code to get started.

System.Diagnostics.Debugger.Launch();

When you activate the feature, a Visual Studio dialog will pop up asking you where you want to debug your process, just choose the Visual Studio project that contains your source code (assuming you already have Visual Studio open with that project).  This is also the technique I use when I need to debug custom stsadm commands.  Once you are done debugging, you will of course want to remove the line launching the debugger.

Comments

 

Links (4/1/2008) « Steve Pietrek’s SharePoint Stuff said:

Pingback from  Links (4/1/2008) « Steve Pietrek’s SharePoint Stuff

April 1, 2008 8:06 PM
 

Another SharePoint Developer/Debugging Tips List « Solutionizing .NET said:

Pingback from  Another SharePoint Developer/Debugging Tips List « Solutionizing .NET

July 11, 2008 8:28 PM
 

Punit said:

Thanks. good tip!

April 12, 2010 5:37 PM
 

Prashanth said:

nice tip ! never knew this one.

April 30, 2010 12:22 PM
 

Hemant said:

thank you very much. your suggestion is live saving

October 12, 2010 6:13 AM
 

bts said:

Thank You, it's ver very useful.

January 26, 2011 3:44 AM
 

Markus said:

thanks, that's really helpful.

I always struggle when it comes to debugging a feature-EventReceiver.

The System.Diagnostics.Debugger.Launch() works like a charm!

October 19, 2011 5:15 AM
 

youngmoony said:

Useful Links 169

March 4, 2012 5:47 PM

Leave a Comment

(required)  
(optional)
(required)  
Add

About CoreyRoth

Corey Roth is an Applications Architect at Infusion specializing in ECM and Search.
2012 dotnetmafia.
Powered by Community Server (Non-Commercial Edition), by Telligent Systems