Friday, May 6, 2011

How to see the exception call stack in SharePoint 2010

SharePoint by default hides any erors that occur, instead displaying a friendly error message. However, during the development process, these error messages are rather unfriendly, since they prevent us from seeing what really goes on.

In SharePoint 2007 we can disable SharePoint's default error habit by making the following changes to the web.config file in the root folder of the web application:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
  <SharePoint>
    <SafeMode CallStack="true"> ⇐ Set CallStack to true
      ...
    </SafeMode>
  </SharePoint>
    ...
  <system.web>
    <customErrors mode="Off" /> ⇐ Set mode to Off
    <compilation debug="true"> ⇐ Set debug to true
    ...
  </system.web>
  ...
</configuration>
This will display exception messages and callstacks in a SharePoint 2007 environment. Try the same changes in SharePoint 2010, and you will still not see the exception.

Dispair not, having done the above you are more than halfway there. What you need to do now is to go to the 14\TEMPLATE\LAYOUTS folder and locate the web.config file here. Then make the following changes:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<configuration>
  <system.web>
    <compilation debug="true"/> ⇐ Set debug to true
    <customErrors mode="Off" /> ⇐ Set mode to Off
    ...
  </system.web>
  ...
</configuration>
This will show you the errors you are making in SharePoint 2010.

No comments:

Post a Comment