December 23, 2015

Could not create instance of type: Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex. No matching constructor was found.

December 23, 2015

Could not create instance of type: Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex. No matching constructor was found.

Okay, that's a long post title.

While configuring a new Sitecore 8.1-Update 1 site that is using Lucene for indexing, I ran into an issue while changing all the indexes to utilize SwitchOnRebuildLuceneIndex.  We do this to allow the system to switch indexes while the new index is rebuilding so that we don't temporarily lose access to an index while it is being rebuilt.  Configuration-wise, we do this by utilizing config transforms.

After building and deploying the solution locally, I was seeing the following nested exception:

Exception: Sitecore.Exceptions.ConfigurationException
Message: Could not create instance of type: Sitecore.ContentSearch.LuceneProvider.SwitchOnRebuildLuceneIndex. No matching constructor was found.
Source: Sitecore.Kernel
   at Sitecore.Configuration.Factory.CreateFromTypeName(XmlNode configNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.Factory.GetInnerObject(XmlNode paramNode, String[] parameters, Boolean assert)
   at Sitecore.Configuration.Factory.AssignProperties(XmlNode configNode, String[] parameters, Object obj, Boolean assert, Boolean deferred, IFactoryHelper helper)
   at Sitecore.Configuration.Factory.CreateObject(XmlNode configNode, String[] parameters, Boolean assert, IFactoryHelper helper)
   at Sitecore.Configuration.Factory.CreateObject(String configPath, String[] parameters, Boolean assert)
   at Sitecore.ContentSearch.ContentSearchManager.get_SearchConfiguration()
   at Sitecore.ContentSearch.ContentSearchManager.GetIndex(String name)
   at Sitecore.Marketing.Search.CampaignDefinitionSearchProvider..ctor(String indexName)

So I had actually recently seen a very similar error while configuring some Solr indexes for a different client.  From that troubleshooting experience, I knew I could crack open the Sitecore.ContentSearch.LuceneProvider assembly to look for the constructor that was having issues.

I could see that the SwitchOnRebuildLuceneIndex constructor accepts three parameters: name, folder and propertyStore.

Upon inspecting my transforms, I came across the Sitecore.ContentSearch.Lucene.Index.Analytics.config file.  This config file specifies the sitecore_analytics_index index, and has four parameters: name, folder, propertyStore and group.  This is more than the SwitchOnRebuildLuceneIndex constructor is expecting.

Workaround/Fix

Don't use SwitchOnRebuildLuceneIndex on the sitecore_analytics_index!  Just leave it as the 'standard' type of Sitecore.ContentSearch.LuceneProvider.LuceneIndex.

As to why this index is different, Patrick notes that the crawlers indexing the analytics data are observers and there is no need to have a secondary index.  Read more in his blog post.