Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharepoint web part: type could not be found/registered as safe

I have a SharePoint web part (essentially just a "Hello World" app) that I just created and am having a problem deploying it. I have signed the .dll, created the .dwp, and registered it as a safe control in web.config. I am able to add it to the Web Part Gallery and add the details for it; however, when I attempt to add it to a page, 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.

Following is my .dwp file:

<?xml version="1.0"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
   <Assembly>SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=################</Assembly>
   <TypeName>MyWebParts.SimpleWebPart</TypeName>
   <Title>My Simple Web Part</Title>
   <Description>A simple Web Part</Description>
</WebPart>

and the entry I added to web.config:

<SafeControl Assembly="SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=################" Namespace="MyWebParts" TypeName="*" Safe="True" />

I also tried using wildcards for the namespace, which didn't help. I have even tried setting the web.config trust level to "Full" (which I would never do in production, but tried to attempt to narrow down the problem) and still had no luck. Any ideas? Thanks.

like image 917
Geo Ego Avatar asked Nov 06 '09 19:11

Geo Ego


1 Answers

One possibility is that types names are not in sync with the .webpart file. For ex.

In the .webpart file:

<?xml version="1.0" encoding="utf-8"?>
<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
    <metaData>
      <type name="Namespace.Class1, $SharePoint.Project.AssemblyFullName$" />

and in the .cs file:

namespace Namespace
{
    public class Class2 : WebPart

and in the SharePointProjectItem.spdata file:

  <SafeControl Assembly="Class2, Version=1.0.0.0, Culture=neutral, PublicKeyToken=9385058ce1ee51a9" Namespace="Namespace" TypeName="*" Safe="True" SafeAgainstScript="False" />

you get the idea: triple-check names consistency across all project artifacts.

like image 137
Ariel Avatar answered Oct 20 '22 01:10

Ariel