June 12, 2012

Debugging Farm and Web Application Scoped Features

I recently started working with farm and web application features for the first time, and naively assumed that since I was using Visual Studio 2010 they would be as easy as any other (lower-level) feature to debug. Oh how I was wrong! I was attempting to debug the farm-scoped feature first, and tried the typical F5 to no avail, then tried again with the "No Activation" project setting. Still no luck. I tried attaching to every process imaginable, and actually did sort of get that to work at one point only to have some other exception completely unrelated to my code be thrown by the vssphost4.exe process.

What DID finally work, is simply adding the line of code below to prompt the user to debug. Of course this is not something you would want to leave in your final code, but it has worked like a charm for both farm-scoped and web application-scoped features. I've actually been deploying the code in my VM (rather than F5 debugging), but it should work either way.


The magic line of code:
System.Diagnostics.Debugger.Launch();

No comments:

Post a Comment