Debugging a feature when using STSADM.EXE

Posted Tuesday, April 1, 2008 10:17 AM by CoreyRoth

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.

Filed under: ,

Comments

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

Tuesday, April 1, 2008 8:06 PM by Links (4/1/2008) « Steve Pietrek’s SharePoint Stuff

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

# Another SharePoint Developer/Debugging Tips List « Solutionizing .NET

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

# re: Debugging a feature when using STSADM.EXE

Monday, April 12, 2010 5:37 PM by Punit

Thanks. good tip!

# re: Debugging a feature when using STSADM.EXE

Friday, April 30, 2010 12:22 PM by Prashanth

nice tip ! never knew this one.

# re: Debugging a feature when using STSADM.EXE

Tuesday, October 12, 2010 6:13 AM by Hemant

thank you very much. your suggestion is live saving

# re: Debugging a feature when using STSADM.EXE

Wednesday, January 26, 2011 3:44 AM by bts

Thank You, it's ver very useful.

# re: Debugging a feature when using STSADM.EXE

Wednesday, October 19, 2011 5:15 AM by Markus

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!

# Useful Links 169

Sunday, March 4, 2012 5:47 PM by youngmoony

Useful Links 169

Leave a Comment

(required)
(required)
(optional)
(required)