Every once in a while when you create a web part or upgrade web part, or do some of things developers do when developing web parts, there comes the chilling moment, when you see an error message such as the one below:
So the question is what do we do in this case? Before you hit the discussion boards, or worse, start pulling your hair, here are couple of tips you can use to troubleshoot the issue:
- Make sure the control is registered as safe in the web.config (duh...actually the error says what it means, right)
- Make sure the assembly is accessible and in the [port]bin folder. (obvious, but worth mentioning)
- Make sure the assembly name in the *.webpart definition file, matches the assembly name in the safe control element in web.config
- Make sure you don't have more than one *.webpart file for the same web part in the web part catalog. This may happen if you changed the name of the *.webpart file.
- Restart IIS to start clean. Attach the debugger to the w3wp.exe process and try to load the page with the rogue web part. This way you can determine the exact location of the assembly you are loading.
- Check if the web part class exists by opening the assembly with reflector. This might sound funny, but in a bigger team, when different versions of assemblies are flying around it is very easy to overlook something and to use the wrong version, which so happens does not contain the web part class at all.
- If you have other tips or suggestions, please add them as comments.
Phew, I think I dodged that one... It turned out I got an older version of the assembly and my web part class was not even there.
Unable to add selected webpart(s). 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.