4

I'm working on Create a Custom Web Part i'm able to do a build and run the new project in debug mode. However, after trying to add the new web part to the site, I get the following error.

"A Web Part or Web Form Control on this Page cannot be displayed or imported. The type could not be found or it is not registered as safe."

I am working on sharepoint 2010

2 Answers 2

14

This is common error if you eg. changed WebPart name after creation and/or changed its namespace.

Since you are working on SharePoint 2010 and most likely with Visual Studio 2010 in VS project:

  1. Select your custom webpart
  2. Use right click > Properties
  3. In properties windows under SharePoint find Safe Control Entries
  4. Click ... button
  5. Verify your settings (namespace)

Retract your solution and delete your web part from Web Part Gallery (this can be your first step). Rebuild, package and deploy your project.

You don't need to edit your web.config manually!

9
  • okay i fix the namespace issue and now i am getting new error An error occurred while attempting to add the item to the page how do check to see what error is that? or do you want me to open a new question let me know.
    – Nick Kahn
    Sep 24, 2011 at 15:47
  • i posted a new question sharepoint.stackexchange.com/questions/20132/…
    – Nick Kahn
    Sep 24, 2011 at 15:57
  • No need for new question. Did you deleted 'old' webpart from web part gallery? If not retract your solution, delete all 'new' and 'old' webpart definitions from gallery and redeploy. If that doesn't solve your problem you can check SharePoint logs (x:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\LOGS) for more info but most likely then you have some specific error in your custom webpart. You need to run in debug mode and check in VS for errors when adding webpart. Sep 24, 2011 at 16:21
  • 1
    i just delete the old web part by going to Site Actions>>Site Settings>>>>Gallary (Web Parts) check my web parts and "Delete Document"
    – Nick Kahn
    Sep 24, 2011 at 16:29
  • 1
    When I ran into this, everything in my assembly was correct. It was caused by me changing the namespace on a webpart that was already in production. I solved the problem with your last paragraph: Removed webpart from the gallery and re-added it, then had to re-add it to all the pages where it was used previously. Thanks!
    – kwill
    May 12, 2017 at 13:06
0

I've experienced this issue several times when deploying custom web parts. If retracting and redeploying doesn't resolve the error (which it likely will not), you can try doing an iis reset. However, I've found that most times, rebooting the server seems to do the trick.

1
  • I have done everything Editing web.config, delete all webaprts from web gallery and re-deploy but could not resolved issues. But tried to add this webapart in another webpart is working in same farm. Anything I need to do? Sep 17, 2021 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.