"Could not find configuration node" Exception When Creating a Content Package

Author

Brandon Bruno

Published

April 22, 2020

Tags

"Could not find configuration node" Exception When Creating a Content Package

I recently tried creating a content package in Sitecore via the package designer. This was on a custom content database called "ContentSync". After adding items, I tried to generate a package but received a yellow screen of death:

An exception while generating a Sitecore content package.

The text version:

Server Error in '/' Application.
Could not find configuration node: databases/database[@id='contentsync']
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Could not find configuration node: databases/database[@id='contentsync']

The takeaway message: Could not find configuration node: databases/database[@id='contentsync']. This is weird, because our configuration definitely has that database defined:

<database id="ContentSync" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
	<param desc="name">$(id)</param>
	<!-- code sample shortened for brevity -->
</database>

Using dotPeek, I dug around the package creation classes, especially Sitecore.Install.Items.ExplicitItemSource and Sitecore.Install.Items.ItemReference. In short, as Sitecore adds items to a package, the database "contentsync" couldn't be found because it's defined as "ContentSync" in configuration. Casing matters for database names!

I've always known that Sitecore database names should always be lowercase, and this is a great example of why.

Sitecore URI 101

The Sitecore package designer uses an item's internal Sitecore URI to determine the database it belongs to. An item's URI is generated with lowercase strings for each segment.

For example, the following PowerShell will get an item's URI:

$item = Get-Item -Path 'contentsync://content/home/my-test-item'
$item.Uri.ToString()

The resulting URI:

sitecore://contentsync/{CD8E1ECD-DC8E-448D-9912-8933768EEC72}?lang=en&ver=1

Package Designer Woes

The package designer grabs the "contentsync" string from the above URI and uses it in an XPath query on Sitecore configuration (in fact, the exact XPath query is actually part of the YSOD exception above: databases/database[@id='contentsync']). Because casing matters in XPath queries, the "ContentSync" database in configuration should have been just "contentsync":

<database id="contentsync" singleInstance="true" type="Sitecore.Data.DefaultDatabase, Sitecore.Kernel">
	<param desc="name">$(id)</param>
	<!-- code sample shortened for brevity -->
</database>

Plenty of other Sitecore code depends on databases having lowercase names, so to ensure consistency and compatibility, always do just that with your database names.

Do you have questions, comments, or corrections for this post? Find me on Twitter: @BrandonMBruno