Skip to content

Getting Error "The given key was not present in the dictionary." #241

@developwithankit

Description

@developwithankit

Hello,

I am facing issue for getting data from SolrCloud using Zookeeper in my Asp.net Application.

I am using this code.

  [TestFixtureSetUp]
  public void Setup1()
  {
    var zookeeperConnectionString = "192.168.0.81:2181";
    var collectionName = "fd_configs";
    Startup.Init<Product>(new SolrCloudStateProvider(zookeeperConnectionString), collectionName);
    Query();
  }

  [Test]
  public void Query()
  {
    var solrCloudMode = ServiceLocator.Current.GetInstance<SolrNet.ISolrOperations<Product>>();
    var results = solrCloudMode.Query(new SolrNet.SolrQueryByField("id", "SP2514N"));
    Assert.AreEqual(1, results.Count);
    Response.Write(results[0].Name);
  }

That line throw an exception:
var solrCloudMode = ServiceLocator.Current.GetInstance<SolrNet.ISolrOperations<Product>>();

Exception Details:
Activation error occured while trying to get instance of type ISolrOperations`1, key ""

Stack Trace:

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

[ActivationException: Activation error occured while trying to get instance of type ISolrCloudStateProvider, key "192.168.0.81:2181"]
   Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +150
   Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(String key) +120
   SolrNet.Cloud.<>c__DisplayClassf`1.<Init>b__d(IContainer container) +100
   SolrNet.Utils.<>c__DisplayClassa`1.<Register>b__9(IContainer c) +66
   SolrNet.Utils.Container.DoGetInstance(Type serviceType, String key) +124
   Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +70

[ActivationException: Activation error occured while trying to get instance of type ISolrOperations`1, key ""]
   Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) +150
   Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance() +116
   _Default.Query() in d:\solrcloudtest_example\Default.aspx.cs:198
   _Default.Setup1() in d:\solrcloudtest_example\Default.aspx.cs:73
   _Default.Page_Load(Object sender, EventArgs e) in d:\solrcloudtest_example\Default.aspx.cs:42
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +92
   System.Web.UI.Control.LoadRecursive() +54
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +772

Please Help.

Thanks in advance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions