Wednesday, October 5, 2011

Cannot import webpart on SharePoint site

When i deploy my Custom WebPart in Dev Environment i got error "Cannot import webpart". This is what I finally figured:
  1. Ensure your feature actually contains the correct version of webpart/assembly.
  2. Ensure safecontrol is correctly defined with correct version
  3. Now, Delete all your solution related webparts from the webpart gallery. (This is what really helped me). You can use a ps script for that.
  4. Redeploy solution. (This will activate the features, but not add the webparts to webpart gallery).
  5. Deactivate the webpart feature either via UI or Disable-SPFeature command (i used ps)
  6. Activate the webpart feature (Enable-SPFeature). This will bring all the new updated webparts to the web part gallery.
  7. Check if the trust level in your web.config file is set to “WSS_Minimal” ? If so, you will have to set it to “medium” as follows:
    <trust level="WSS_Medium" originUrl="" />
The above is especially useful if you change your classname, namespace or versions. Now I was able to import the webpart fine. I also found this method is consistent. So I added the Delete webparts and Disable, Enable features as part of my deployment script.

No comments:

Post a Comment