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” %>

3 thoughts on “Master Page Error from Exporting file from SharePoint Designer”

  1. Since the File -> Export or File -> Save As approach can lead to those errors and is a lot of work if you have to move several files I created a little Powershell function that will simply export items that ‘live’ either in the Master Page Gallery or the Style Library and have been checked out to the file system.I chose to use the ‘Checked out’ status as an indicator that the file was probably modified and needs to be transfered to the solution (wsp).Here is the Powershell function :<snip>function Export-CheckedOutItems { param( [string]$url = $(Throw “Parameter ‘Url’ cannot be empty.”), [string]$path = “C:Exported SharePoint Files” ) $listNames = “Master Page Gallery”, “Style Library” $site = new-object Microsoft.SharePoint.SPSite($url) $web = $site.RootWeb foreach($list in ($web.lists | where-object {$listNames -contains $_.Title})) { foreach($listItem in $list.Items | where-object {$_.File.CheckOutStatus -ne “None”}) { $file = $listItem.File $file.Name $childPath = Join-Path -path $path -childpath $file.ParentFolder.Url if((test-path $childPath) -eq $False) { new-item -path $childPath -type directory } $fileName = Join-Path -path $childPath -childpath $file.Name $stream = new-object IO.FileStream($fileName, [IO.FileMode]::Create, [IO.FileAccess]::Write) $bytes = $file.OpenBinary() $stream.Write($file.OpenBinary(),0,$bytes.Length) $stream.Close() } } Write-Host “Process completed !” }</snip>To use it you will have to make a Sharepoint assembly accessible in Powershell :[System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)

  2. This is a good tip, but the tough part about this issue is that if you’re developing on a server (or even if it’s just a different directory) than the location that it’s actually going to be posted on, this happens to page layouts/master pages that have web parts outputting xml (which is a lot of them!). I wish that SharePoint publishing sites were easier to migrate!If you have any additional tips, please keep them coming! Thank you for posting about this error 🙂

Comments are closed.