I’ve been working on a SharePoint 2010 web part project and when I pressed F5 to debug, I ran across the error: “A Web Part or Web Form Control on this Page cannot be displayed or imported. The type is not registered as safe.”
This can be caused by innocently renaming your assembly/namespaces/classes. The first thing to check is: SharePointProjectItem.spdata. Your web part should be properly referenced in the SafeControl section.
<ProjectItemFile Source="VisualWebPart1UserControl.ascx" Target="CONTROLTEMPLATES\VisualWebPartProject2\VisualWebPart1\" Type="TemplateFile" />
</Files>
<SafeControls>
<SafeControl Name="SafeControlEntry1" Assembly="$SharePoint.Project.AssemblyFullName$" Namespace="VisualWebPartProject2.VisualWebPart1" TypeName="*" IsSafe="true" IsSafeAgainstScript="false" />
</SafeControls>
</ProjectItem>
You can also get this error if you've added a web part to a page (e.g., debugging) and then the web part has been removed from the gallery.
If that doesn't resolve it, check your other files.
e.g. VisualWebPart1.webpart file:
<type name="VisualWebPartProject2.VisualWebPart1.VisualWebPart1, $SharePoint.Project.AssemblyFullName$" />
VisualWebPart1.ascx.cs namespace name
namespace VisualWebPartProject2.VisualWebPart1
{
public partial class VisualWebPart1UserControl : UserControl
{
VisualWebPart1.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VisualWebPart1UserControl.ascx.cs" Inherits="VisualWebPartProject2.VisualWebPart1.VisualWebPart1UserControl" %>
VisualWebPart1.cs
namespace VisualWebPartProject2.VisualWebPart1
{
[ToolboxItemAttribute(false)]
public class VisualWebPart1 : WebPart
Elements.xml
<File Path="VisualWebPart1\VisualWebPart1.webpart" Url="VisualWebPartProject2_VisualWebPart1.webpart" Type="GhostableInLibrary" >
Assemblyinfo.cs
[assembly: AssemblyTitle("VisualWebPartProject2")]
...
[assembly: AssemblyProduct("VisualWebPartProject2")]
1 comment:
what about SharePointProjectItem.spdata file ?
Post a Comment