The file or folder name contains characters that are not permitted

This is a very misleading error message to get, especially when the cause and solution has NOTHING related to what the message is referring to.

I came across this error while attempting to deploy my site definition. I added a few things to my site definition, one of these was a aspx page referring to my master page.

The error:

<%@ Page language=”C#” MasterPageFile=~masterurl/custom.master” …../>

The fix:

<%@ Page language=”C#” MasterPageFile=”_catalogs/masterpage/custom.master” …../>

Done!

Deployment error: failed to load due to invalid xml: Name cannot begin with ‘%’

The situation when I come across this error is during the deployment and activation of a master page. The problem is that I added the .masterpage file as an element manifest rather than an element file in the Feature.xml definition that deploys the master page to a site collection.

The solution:

Add the .masterpage file as an element file not as a element manifest in the Feature.xml definition!