Troubleshoot Sitecore Could not create instance of type errors

  • Twitter
  • LinkedIn

Troubleshoot Sitecore Could not create instance of type errors

When I have been setting up Solr in Sitecore with Commerce server I have been receiving several exceptions with create instance or create object errors. Below are some steps to identify and fix the errors. "Could not create instance of type: InsitePlusSitecore.Core.Repositories.ProductClassificationRepository. No matching constructor was found." "Could not create instance of type: System.Boolean. No matching constructor was found."
If you are setting up a solr instance with Sitecore the first step I recommend taking is to check for any Lucene configuration files that have not been disabled. To verify that all the lucene config files are disabled run the following line.
Note: Make sure to replace C:\inetpub\wwwroot\sc81 with the path to the sitecore directory.

dir C:\inetpub\wwwroot\sc81\*lucene*.config /s

The second approach to resolving the "could not create instance of type error" requires to add the following two files to your project. Click here to download the file.
The class has been updated to catch the exceptions thrown for CreateObject and log the config xml to the log. The xml file will be used to identify the configuration that is causing the issue.

public static object CreateObject(XmlNode configNode, string[] parameters, bool assert, IFactoryHelper helper)
{
	Assert.ArgumentNotNull((object)configNode, "configNode");

	try
	{
		//Original logic
	}
	catch(Exception e)
	{
		Log.Fatal("Failed to create object: " + configNode.OuterXml, e, new object());
		throw e;
	}
}

Next we need to add a statement to the application start in the global asax file. Below is a basic global asax file.

using Sitecore.ContentSearch;
using XCommerce;

namespace Website
{
    public class Global : Sitecore.Web.Application
    {
        protected void Application_Start()
        {

        }
    }
}

The application start will need to register the new custom factory.

            CustomFactoryWrapper factoryWrapper = new CustomFactoryWrapper();
            ContentSearchManager.Locator.Register(c => factoryWrapper);

After the above changes have been made the xml configuration that is causing the exception will be included in the logs. With this xml content you are able to identify the xml code that is causing the error.

Related Blogs

Latest Blogs