Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I keep getting this error when I try to add a web part that I added through a WSP:

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

I installed this through the Management Shell:

Install-SPSolution -Identity mySolution.wsp -WebApplication http://sp-dev:10000 -GACDeployment

Is there something I need to do differently with my WSP in order to get this error message to go away? I would prefer a solution that allows me to solve this through my WSP if possible.

UPDATE:

Ok, I marked the additional assembly as a Safe Control and now my manifest looks like this. I noticed that the Safe Controls node under my third party assembly (DocX.dll) is the same as my Safe Control node under my main project (except for namespace). Is this correct?

  <Assemblies>
    <Assembly Location="DocX.dll" DeploymentTarget="GlobalAssemblyCache">
      <SafeControls>
        <SafeControl Assembly="MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=161g332b2e4d265e" Namespace="Novacode" TypeName="*" />
      </SafeControls>
    </Assembly>
    <Assembly Location="MyProject.dll" DeploymentTarget="GlobalAssemblyCache">
      <SafeControls>
        <SafeControl Assembly="MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=161g332b2e4d265e" Namespace="MyProject.MyProject" TypeName="*" />
      </SafeControls>
    </Assembly>
  </Assemblies>
share|improve this question
    
Is there a Strong Name Key (.snk) in your project that is being used to sign your assemblies? –  Tim Gabrhel Apr 20 '11 at 4:19
    
Yes, I have that already. –  Abe Miessler Apr 20 '11 at 5:05
    
it is cause usually by renaming a webpart and its classes by hand. add a clean Visual Webpart and copy paste the main ascx and codes –  imanabidi Jul 2 at 4:37

3 Answers 3

up vote 8 down vote accepted

Sounds like you are missing the <SafeControl> element from your package. Normally it is added for you if you create it in VS2010. But if your web part/control is in another assembly you may have to add it manualy

http://msdn.microsoft.com/en-us/library/ms412965.aspx

Something like this should go in your Package.Template.xml file (Solution explorer -> Package -> Open -> Manifest -> Edit Options)

    <Assemblies>
      <Assembly
        DeploymentTarget="GlobalAssemblyCache"
        Location="Text">
        <SafeControls>
           <SafeControl
             Assembly = "Text"
             Namespace = "Text"
             Safe = "TRUE" | "FALSE"
             TypeName = "Text"/>
        </SafeControls>
      </Assembly>
    </Assemblies>

Can you tell us a little about what controls/webparts are in the wsp?

Example default package preview has this:

<Solution xmlns="http://schemas.microsoft.com/sharepoint/" SolutionId="7905031d-87a1-47b3-b631-c93daff7e4c7" SharePointProductVersion="14.0">
  <Assemblies>
    <Assembly Location="SharePointProject1.dll" DeploymentTarget="GlobalAssemblyCache">
      <SafeControls>
        <SafeControl Assembly="$SharePoint.Project.AssemblyFullName$" Namespace="SharePointProject1.WebPart1" TypeName="*" />
      </SafeControls>
    </Assembly>
  </Assemblies>
  <FeatureManifests>
    <FeatureManifest Location="SharePointProject1_Feature1\Feature.xml" />
  </FeatureManifests>
</Solution>
share|improve this answer
    
There is only one visual web part in the WSP, but it IS using a third party assembly for some functionality. I added that to my "Additional Assemblies" and I notice that it has "No" set under Safe controls. Could this be the problem? –  Abe Miessler Apr 20 '11 at 4:57
    
if the visual webpart uses controls in the third party assembly, then yes. Remember that the Assembly property needs to be the FullName (including the version etc) –  djeeg Apr 20 '11 at 5:16
    
Awesome, take a look at my update. Does that look correct? –  Abe Miessler Apr 20 '11 at 5:31
    
the first Assembly should be the FullName of DocX.dll –  djeeg Apr 20 '11 at 7:06

Visual Studio has a bug where changing the namespace of your class does not update the manifest file of the installation package. Then when you install the safe control and execute your webpart, it is missing due to a namespace mismatch.

For example:

<SafeControl Assembly="Sharepoint_Native_Indicators, Version=1.0.0.0,
                       Culture=neutral, PublicKeyToken=cd7250552f7daf2e"
             Namespace="XXXXX.YYYYYY" TypeName="*" />
share|improve this answer

Dont forget to check the SharePointProjectItem.spdata file too. Most of them miss this. The namespace here may not get updated if you changed it in just the code files.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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