Posted by Administrator
While trying to use my custom layouts page, I received an exception that indicated that my custom class was not registered as a safecontrol in the web.config.
Process ID: 5272
Process name: w3wp.exe
Account name: DEV\spAppPool
Exception type: HttpParseException
Exception message: Could not load type 'Capgemini.SharePoint.Pex.Example.Layouts.Capgemini.SharePoint.Pex.Example.@default'.
I was confused, didn't visual studio created the SafeControls elements for me? WSPBuilder did it for me in the past so why won't visual studio do it for me?
Actually it can but it doesn't by default, Microsoft provided a nice and easy visual studio interface for us. So here it goes...
1. Open package.package in your visual studio project
2. Notice the 3 tabs (Design,Advanced and Manifest), Click on the manifest tab
3. You’ll see that your SafeControl element is not listed in the manifest, if it does, than you don’t have to complete this tutorial because everything is already in place
4. Click on the Manifest tab
5. Provide the following code inside the Assembly Element
This results in
You'll notice that I’ve used 2 special elements in the xml
These 2 parameters are new in visual studio 2010 SharePoint development. Replaceable parameters, or tokens, can be used inside project files to provide values for SharePoint solution items whose actual values are not known at design time. They are similar in function to the standard Visual Studio template tokens
Check the related link at the bottom of this post for the MSDN website.
More information regarding replaceable parameters
The name of the containing project file, such as, "NewProj.csproj".
The name of the containing project file without the file name extension. For example, "NewProj".
The display name (strong name) of the containing project’s output assembly.
The name of the containing project’s output assembly.
The name of the containing project’s output assembly, without the file name extension.
The public key token of the containing project’s output assembly, converted to a string. (16-characters in "x2" hexadecimal format.)
The name of the containing package.
The name of the containing package's definition file.
The name (without extension) of the containing package's definition file.
The SharePoint ID for the containing package. If a feature is used in more than one package, then this value will change.
The name of the definition file of the containing feature, such as Feature1.feature.
The name of the feature definition file, without the file name extension.
The name of the folder that contains the feature in the package. This token equates to the "Deployment Path" property in the Feature Designer. An example value is, "Project1_Feature1".
The SharePoint ID of the containing feature. This token, as with all feature-level tokens, can be used only by files included in a package via a feature, not added directly to a package outside of a feature.
The name of the project item (not its file name), as obtained from ISharePointProjectItem.Name.
The assembly qualified name of the type matching the GUID of the token. The format of the GUID is lowercase and corresponds to the Guid.ToString(“D”) format (that is, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).
The full name of the type matching the GUID in the token. The format of the GUID is lowercase and corresponds to the Guid.ToString(“D”) format (that is, xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx).