There I was, minding my own business when I was greeted by this lovely YSOD. I was creating a new site within my custom SiteProvider for a client and when I loaded up Sitecore, everything was down. From the stack trace, it was clear that it was cache related. Some query to the cache configuration was breaking everything. To test this, I created a XML-based site configuration:
<site name="12-monkeys" virtualFolder="/12-monkeys" physicalFolder="/12-monkeys" rootPath="/sitecore/content" startItem="/home2" database="web" htmlCacheSize="50MB" registryCacheSize="0" viewStateCacheSize="0" xslCacheSize="25MB" filteredItemsCacheSize="10MB" />
Everything was fine. A big more digging had me remove the cache sizes in the site definition.
<site name="12-monkeys" virtualFolder="/12-monkeys" physicalFolder="/12-monkeys" rootPath="/sitecore/content" startItem="/home2" database="web" />
Boom. The error is back. It appears that when it tries to default a cache size, it explodes. I renamed “12-monkeys” to “twelve-monkeys” and the error went away. Interesting.
Time to open up dotPeek. Down inside Sitecore.Web.SiteInfo, there’s a method to create all the caches which is called as part of the constructor. When this is called, there’s a method invoked that will get the cache size from the site.
private long GetCacheSize(string attribute, Sitecore.Collections.StringDictionary properties, long defaultSize) { Assert.ArgumentNotNull((object) attribute, "attribute"); Assert.ArgumentNotNull((object) properties, "properties"); string str1 = StringUtil.GetString(new string[1] { properties[attribute] }).ToUpperInvariant(); if (str1.Length > 0) return StringUtil.ParseSizeString(str1); string str2 = Factory.CreateObject("cacheSizes/sites/" + this.name + "/" + attribute.Substring(0, attribute.Length - "CacheSize".Length), false) as string; if (!string.IsNullOrEmpty(str2)) return StringUtil.ParseSizeString(str2); return defaultSize; }
Noting line 11, you can see it tries to build an XPath to the cacheSizes node:
<cacheSizes> <sites> <website> <html>50MB</html> <registry>0</registry> <viewState>0</viewState> <xsl>25MB</xsl> </website> </sites> </cacheSizes>
Creating a website in here with a name that starts with a number is against the W3 standards for XML and would break the whole entire world.
I’ll be submitting this as a bug to the Sitecore Support Portal, but in the interim, I suggest you always specific your cache sizes if you’re going to have the possibility of a site name that starts with a number.
Update 5.16: Sitecore’s official response was to always include the cache settings on the site definition node. That’s about right, I guess.