简体   繁体   中英

The given key was not present in the dictionary. - Exception Solrnet and CommonServicelocator

We are using SolrNet in Sitecore CMS , which also has a wrapper over the Solr. But to leverage the features in SolrNet , we have preferred to use Solrnet.

I have upgraded this sitecore application and it looks like it also initializes a ServiceLocator for Solr. this is clashing with the Solrnet ServiceLocator. Below is the code and error stack trace we are using for initalizing Solrnet. I am not sure how to debug or resolve this error, request anyone to please provide some pointers for this or has seen this error before.

Startup.Init(loggingSolrConnection);

Solrnet version - 1.0.13 , also tried with latest 1.0.19. Bin folder contains - Commonservicelocator.dll and CommonServicelocator.solrnet.dll

The given key was not present in the dictionary.
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.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:
[KeyNotFoundException: The given key was not present in the dictionary.]
   System.ThrowHelper.ThrowKeyNotFoundException() +36
   System.Collections.Generic.Dictionary`2.get_Item(TKey key) +52
   SolrNet.Utils.Container.DoGetInstance(Type serviceType, String key) +25
   CommonServiceLocator.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +54

[ActivationException: Activation error occurred while trying to get instance of type ISolrMoreLikeThisHandlerQueryResultsParser`1, key ""]
   CommonServiceLocator.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +155
   CommonServiceLocator.ServiceLocatorImplBase.GetInstance() +54

Sitecore is designed to abstract search engine implementation from the developer, so that Solr/Azure Search/Elastic Search/Coveo/(any other engine) could be used under the hood.

Although the error indicates a lack of ISolrMoreLikeThisHandlerQueryResultsParser registration that ought be added to OOB Sitecore via Sitecore.ContentSearch.SolrProvider.SolrNetIntegration.DefaultSolrLocator.Initialize or to SOLR native via SolrNet.Startup.InitContainer API, I would encourage you to avoid dealing with SOLR directly and use Sitecore APIs instead .

Otherwise you might experience different behavior caused by bypassing Sitecore logic.

Could you please brief the reasons/use cases when OOB Sitecore API is not enough?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM