sharepointmosssharepoint-2007

"CallList: Cannot import this Web Part" when installing SharePoint Web Part


I have created a WebPart. When I add the WebPart to a page I get the error below. Error MEssage

If I delete what is in my constructor for my WebPart it will then add to the page. Then if I deploy my code with the WebPart all ready on a page the WebPart will display correctly. I can't add it to other pages I get the error before.

So I presume that there is a problem with the constructor. The line that is breaking it is

var site = new SPSite("http://website/site");

This has been found by commenting code out. Can you not create an SPSite when installing a WebPart?


Solution

  • Do you have your constructor code wrapped in a try/catch block? It may be throwing an exception for some reason.

    Otherwise, try moving your constructor code to OnInit to see if that makes a difference.