WSS Dev: HowTo debug a WebPart

Can you debug a webpart in a WSS page? Yes – not a problem.

Prerequisites:

  • From WSPBuilder make your Webpart (WP). See here.
  • Activate the feature containing the WP
  • Add the WP to a site page
  • Open the page in a browser

Debug:

  • In VisualStudio (VS) set a breakpoint in your WP code
  • RightClick (RC) project – Build (Shift+F6)
  • RC project – WSP – Copy2Gac
  • (RC project – WSP – Recycle) => w3wp.exe will be shutdown and a new one will be created when a request to a page is done.
  • RC project – WSP – Attach – choose w3wp.exe (the one with sql…?) => The breakpoint will be unfilled and not yet be reachable
  • Refresh the browser (F5) => this will load debug info
  • VS: Stop debugging (shift+F5)
  • RC project – WSP – Attach – choose w3wp.exe
  • Refresh the browser (F5) => now your breakpoint will be filled and reached

Thanx to Erik Norström.

In addition you would like to have following set in the web.config for your WebApp:

<?xml version="1.0"?>
<configuration>
  <SharePoint>
    <SafeMode CallStack="true" AllowPageLevelTrace="true">
      <PageParserPaths>
      </PageParserPaths>
    </SafeMode>
  </SharePoint>
  <system.web>
    <!--
        Enable ASP.NET debugging.
        Set compilation debug="true" to insert debugging
        symbols into the compiled page.
    -->
    <compilation batch="false" debug="true">
    </compilation>
    <!--
        The <customErrors> section enables configuration
        of what to do if/when an unhandled error occurs
        during the execution of a request.
    -->
    <customErrors mode="Off">
    </customErrors>
  </system.web>
</configuration>

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: