The exception was thrown because the ContentReference.SiteBlockFolder (line 4) was set to non-existing content for one of our two websites in the EPiServer installation; i.e. a content with id 501, which didn’t exist in our template database.

Reverting the code base to a pre-EPiServer Forms commit, and having a look in EPiServer’s edit mode confirmed this. The left pane in the image below is the site with the faulty SiteBlockFolder reference, and the right one is the site where everything was working as it should.

Resetting EPiServer’s Content Folders to get ‘For All Sites’, ‘For This Site’, ‘For this Page’ back

The solution is rather simple. In EPiServer’s Admin mode (Config tab, and Manage Websites option) you have a checkbox called Use site-specific assets if you access the non-working website’s settings. Thanks Thomas Durrani.

Simply click it, save the settings, click it again and save – and your references should be repaired by the EPiServer installation.

This is also confirmed if we have a look in the EPiServer database table tblSiteDefinition.

The first website was the one with the faulty reference. It’s SiteAssetsRoot value was previously set to 501, but was automatically changed to the working reference 542.