【问题标题】:The given key was not present in the dictionary. - Exception Solrnet and CommonServicelocator字典中不存在给定的键。 - 异常 Solrnet 和 CommonServicelocator
【发布时间】:2020-01-13 10:03:00
【问题描述】:

我们在 Sitecore CMS 中使用 SolrNet,它还有一个对 Solr 的包装器。但是为了利用 SolrNet 中的功能,我们更喜欢使用 Solrnet。

我已经升级了这个 sitecore 应用程序,它看起来也为 Solr 初始化了一个 ServiceLocator。这与 Solrnet ServiceLocator 冲突。下面是我们用于初始化 Solrnet 的代码和错误堆栈跟踪。我不知道如何调试或解决此错误,请任何人为此提供一些指示或以前见过此错误。

Startup.Init(loggingSolrConnection);

Solrnet 版本 - 1.0.13 ,也尝试使用最新的 1.0.19。 Bin 文件夹包含 -Commonservicelocator.dllCommonServicelocator.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

【问题讨论】:

标签: solr sitecore solrnet service-locator common-service-locator


【解决方案1】:

Sitecore 旨在从开发人员那里抽象出搜索引擎实现,以便在后台使用 Solr/Azure Search/Elastic Search/Coveo/(任何其他引擎)。

虽然错误表明缺少ISolrMoreLikeThisHandlerQueryResultsParser 注册,应该通过Sitecore.ContentSearch.SolrProvider.SolrNetIntegration.DefaultSolrLocator.Initialize 添加到OOB Sitecore 或通过SolrNet.Startup.InitContainer API 添加到SOLR 本机,但我建议您避免直接处理SOLR 并使用Sitecore APIs instead .

否则,您可能会遇到因绕过 Sitecore 逻辑而导致的不同行为。

能否请您简单介绍一下OOB Sitecore API 不够用的原因/用例?

【讨论】:

  • 嗨@Nikolay,这是继承自 Sitecore 8.x 版本的应用程序代码库,现在正在升级到 Sitecore 9.2,我相信 SolrNet 的使用是为了利用一些功能,例如(POST 请求而不是GET),这在 Sitecore.ContentSearch 中不可用 OOTB。另外,我想补充一下 SolrNet 在 Sitecore 8.x 应用程序中运行良好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-18
  • 1970-01-01
  • 1970-01-01
  • 2016-08-14
相关资源
最近更新 更多