问题
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