SolrNet - The given key was not present in the dictionary

旧街凉风 提交于 2019-12-13 02:57:41

问题


I'm using SolrNet with vb.net 2.0 and can't seem to instantiate solr.

Dim solr As ISolrOperations(Of PMWProperty) = ServiceLocator.Current.GetInstance(Of PMWProperty)()

throws the exception:

[KeyNotFoundException: The given key was not present in the dictionary.] System.ThrowHelper.ThrowKeyNotFoundException() +28 System.Collections.Generic.Dictionary`2.get_Item(TKey key) +7456108 SolrNet.Utils.Container.DoGetInstance(Type serviceType, String key) +22 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +47

[ActivationException: Activation error occured while trying to get instance of type PMWProperty, key ""] Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +104 Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance() +5

I have a class PMWProperty with only a few fields that match to my solr schema. I can run queries through the solr url just fine (localhost:8983/solr), but can't get it working in my code.

What key is it looking at? The exception seems to say that the key is "", but what should it be? Why do I need a key?


回答1:


You need to get ISolrOperations(Of PMWProperty) from the service locator, not PMWProperty, so the code should look like this:

Dim solr As ISolrOperations(Of PMWProperty) = ServiceLocator.Current.GetInstance(Of ISolrOperations(Of PMWProperty))()


来源:https://stackoverflow.com/questions/4751773/solrnet-the-given-key-was-not-present-in-the-dictionary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!