Error: Cannot Import this Web Part

If you get the following error message when attempting to add a web part to a page, it’s not that helpful is it. This post on Microsoft TechNet (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2362666&SiteID=1) contains a good response from MVP Robert Bogue which details some things to try to resolve the issue, however, it can be tough to locate the source of the problem without much detail.

image

A good way to get additional detail around the error message is to do the following.

Go to Site Settings > Galleries > Web Parts

And click on the web part linked title. This will go to the web part preview. When a web part is working fine, the web part will display in the page. However, for broken web parts that give the mysterious error shown above, it will give you the actual error itself, as shown below, provided you have your debug settings on correctly within your web.config

clip_image001

web.config Debug settings for development

When developing in SharePoint, it is always a good idea to make a few changes to your web.config so that you can actually get some useful error messages when things do not go as planned.

To do so, locate the web.config for the web application you are working on (for example: C:\Inetpub\wwwroot\wss\VirtualDirectories\site.com80\web.config) and make the following changes:

  1. Locate CallStack="false" and set it to true: CallStack="true"
  2. Locate customErrors mode="On" and set that to Off: customErrors mode="Off"
  3. Locate compilation batch="false" debug="false", and then set those both to true: compilation batch="true" debug="true"

And that should do the trick to give you some useful debug messages in SharePoint!