Master Page Error from Exporting file from SharePoint Designer

If you are using SharePoint Designer (SPD) to create a master page file that will then be placed on the web server for use, such as with a custom site definition or custom Feature, you may run into the following error when viewing or creating a new site:

Cannot convert type ‘Microsoft.SharePoint.WebControls.ScriptLink’ to ‘System.Web.UI.IAttributeAccessor’

This may be caused by the method you used to get your custom master page file out of the content database. If you used the Export feature in SPD (File –> Export –> File), SPD will add in a bunch of code that only SPD knows how to properly read and process.

For example, if you look at the HEAD area of your master page file in SPD, you will probably see something like:

<SharePoint:ScriptLink language=”javascript” name=”core.js” Defer=”true” runat=”server”/>
<SharePoint:CustomJSUrl runat=”server”/>
<SharePoint:SoapDiscoveryLink runat=”server”/>
<SharePoint:CssLink runat=”server”/>
<SharePoint:Theme runat=”server”/>

After you export the file, if you look at the code in Notepad, now the code looks like this:

<SharePoint:ScriptLink language=”javascript” name=”core.js” Defer=”true” runat=”server” __designer:Preview=”&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;/_layouts/1033/init.js?rev=ck%2BHdHQ8ABQHif7kr%2Bj7iQ%3D%3D&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; src=&quot;/_layouts/1033/core.js?rev=S5dt4K8TJGVTYU9HrW6enw%3D%3D&quot; defer&gt;&lt;/script&gt;
” __designer:Values=”&lt;P N=’Language’ T=’javascript’ /&gt;&lt;P N=’Name’ T=’core.js’ /&gt;&lt;P N=’Defer’ T=’True’ /&gt;&lt;P N=’InDesign’ T=’False’ /&gt;&lt;P N=’ID’ T=’ctl01′ /&gt;&lt;P N=’Page’ ID=’1′ /&gt;&lt;P N=’TemplateControl’ ID=’2′ /&gt;&lt;P N=’AppRelativeTemplateSourceDirectory’ R=’-1′ /&gt;”/>
<SharePoint:CustomJSUrl runat=”server” __designer:Preview=”” __designer:Values=”&lt;P N=’InDesign’ T=’False’ /&gt;&lt;P N=’ID’ T=’ctl02′ /&gt;&lt;P N=’Page’ ID=’1′ /&gt;&lt;P N=’TemplateControl’ ID=’2′ /&gt;&lt;P N=’AppRelativeTemplateSourceDirectory’ R=’-1′ /&gt;”/>
<SharePoint:SoapDiscoveryLink runat=”server” __designer:Preview=”&lt;link type=&quot;text/xml&quot; rel=&quot;alternate&quot; href=&quot;/_vti_bin/spsdisco.aspx&quot; /&gt;” __designer:Values=”&lt;P N=’InDesign’ T=’False’ /&gt;&lt;P N=’ID’ T=’ctl03′ /&gt;&lt;P N=’Page’ ID=’1′ /&gt;&lt;P N=’TemplateControl’ ID=’2′ /&gt;&lt;P N=’AppRelativeTemplateSourceDirectory’ R=’-1′ /&gt;”/>
<SharePoint:CssLink runat=”server” __designer:Preview=”&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/_layouts/1033/styles/core.css&quot;/&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;/_layouts/1033/styles/mystyles.css&quot;/&gt;
” __designer:Values=”&lt;P N=’InDesign’ T=’False’ /&gt;&lt;P N=’ID’ T=’ctl04′ /&gt;&lt;P N=’Page’ ID=’1′ /&gt;&lt;P N=’TemplateControl’ ID=’2′ /&gt;&lt;P N=’AppRelativeTemplateSourceDirectory’ R=’-1′ /&gt;”/>
<SharePoint:Theme runat=”server” __designer:Preview=”” __designer:Values=”&lt;P N=’Name’ R=’-1′ /&gt;&lt;P N=’InDesign’ T=’False’ /&gt;&lt;P N=’ID’ T=’ctl05′ /&gt;&lt;P N=’Page’ ID=’1′ /&gt;&lt;P N=’TemplateControl’ ID=’2′ /&gt;&lt;P N=’AppRelativeTemplateSourceDirectory’ R=’-1′ /&gt;”/>

When the master page file is placed on the web server and used, it will generate the error listed above.  To fix this issue, don’t export out the file from SPD.  Instead just copy the code from SPD to an empty text file outside of SPD and then name it appropriately (mysite.master).

In some cases, when you do a manual code copy like this, control template paths are altered and that will need to be fixed prior to using the file.  It is always a good practice to double check this when you take your code out of SPD.  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=”/Welcome.ascx” %>