The Sitecore.Client.ContentDatabase is null.

While working on the project related to content testing, I was greeted with this error when I opened a page that has a page test running.

While checking the item, I found out that certain renderings were using custom data-sources that were resolved in EnterRenderingContext Pipeline. When I removed these custom data-sources, the page started loading without any issues.

The next step was to decompile the Sitecore.ContentTesting.dll and tracing the error to figure out where the code was breaking.

This was the statement that was causing the issue.

return RuleFactory.ParseRules<ConditionalRenderingsRuleContext>(renderingItem != null ? renderingItem.Database : Client.ContentDatabase, renderingDefinition.Rules);

So basically, if the rendering item was null, the ParseRules function should be passed ContentDatabase which was somehow null for the request. My initial instinct was to override the code with my custom code to handle this issue but I decided to do a little research before doing so.

After going through StackOverflow and Sitecore documentation, I found these two articles which specified the difference between Context Database and Content Database. It also listed some scenarios where the Content Database would be empty.

As suggested, I updated the SiteDefination as follows and the page started loading fine.

<site name="site" patch:before="site[@name='website']"

So as it turns out if you want to use custom data-sources during content testing, it's better to specify the content database in your Site Definitions.

Leave a Reply

Your email address will not be published. Required fields are marked *