Tuesday, September 14, 2004

 

SharePoint Errors

Ok, I am finding this out the hard way, but I am telling this to everyone so you don’t have to go through the same frustration. The errors that SharePoint gives can be very misleading!

Since yesterday I have been trying to figure out why SharePoint keeps complaining that my web part is not marked as safe even though I have setup the whole site as part of WSS_Medium security and marked the assembly as safe (I have made sure 100s of times that the web.config is correct). Below is the actual error that I was getting:

A Web Part or Web Form Control on this Web Part Page cannot be displayed or imported because it is not registered on this site as safe.

Logically you would think that there is something wrong with how the web part is configured, or maybe there is something wrong with the web.config, or wait it could even be something with the Virtual PC running SharePoint. But… that’s not the case :-/

After spending a long time and after creating several different web parts with several different approaches hoping it would like one (including some with the default names like WebPart1, WebPartLibrary, etc.) I figured out that it was the class constructor!! I mistakenly did not put the scope classifier for the constructor and SharePoint wasn’t able to construct the class, but for some reason it decided that the web part was not marked as safe!

Lesson: be very careful when SharePoint complains, some times the actual problem isn't what it is says it is!

Comments:
Hi
I have same problem as u described.
but I couldn't understand where exactly I have to look for problem!
would you plz describe more for me?

thx
Amir
amir.mehrani@gmail.com
 
Hi Amir,

In my case I just forgot to put the `public` qualifier before the constructor. But I would assume that SharePoint would give similar message if one of the interface methods isn't qualified correctly so make sure that all the necessary functions are accessible.

I don't remember exactly but by default if you put your web part in the bin folder then it will not have permissions to access either part or most of the Microsoft.SharePoint namespace. So make sure that you do one of the following if you have to access this namespace:
1. Strongly name your assembly and add to the SafeControls in web.config.
2. If you are working on a dev machine then you can just change the default permission level.

Good luck!
 
Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?