Friday, June 1, 2012

Cannot Convert Type Microsoft.SharePoint.WebControls.CSSRegistration to System.Web.UI.IAttributeAccessor – Beware of this in custom master page for custom publishing site definition

When you create site definition or custom master page as feature you may face error like:

Cannot Convert Type Microsoft.SharePoint.WebControls.CSSRegistration to System.Web.UI.IAttributeAccessor – Beware of this in custom master page for custom publishing site definition.
Reason:
When you export master page through SharePoint designer or WebDAV, It will add designer attributes (__designer) which will cause these problem.
<SharePoint:FieldValue FieldName="Title" runat="server" __designer:Preview="XXXXX" __designer:Values="XXXXX"/>

Also when open custom physical master page in SharePoint designer it adds __designer:Preview and __designer:Values attributes to my FieldValue and Literal controls, and if I don't remove them before check in ASP.NET complains.

 Also It may occur when you use html tags as below:

<a href="<%$SPUrl:~sitecollection/Pages/YourLink.aspx%>" >View All</a>

check url:
http://vyeung.wordpress.com/2011/06/01/sharepoint-designer-2010-addinggenerating-__designer-preview-tags-a-fix-to-solve-this-issue/


Solutions:
  1. Copy content instead of export from SPD.
  2. Double Check file and make sure you removed these attributes (__designer) 
  3. Look at the page directives in the top of the file, and ensure that a tilde and forward slash are present in the path(s):
    <%@ Register TagPrefix="wssuc" TagName="Welcome" src="~/_controltemplates/Welcome.ascx" %>

No comments: