title: The given key was not present in the dictionary solrnet
body: <p>Please note: I know for the question <a href="https://stackoverflow.com/questions/4751773/solrnet-the-given-key-was-not-present-in-the-dictionary">SolrNet - The given key was not present in the dictionary</a> and I have initialized solr object just like Mauricio suggests.</p>
  
  <p>I am using solr 4.6.0 and solrnet build #173, .net framework 4.0 and VS2012 for development. For some unknown reason I am receiving error 'The given key was not present in the dictionary'. I have a document with that id in solr, I've checked via browser. It's a document like any other document. Why is error popping up? My code (I've made a comment on the place where the error happens):</p>
  
  <pre><code>//establishes connection with solr
          private void ConnectToSolr()
          {
              try
              {
                  if (_solr != null) return;               
                  Startup.Init&lt;Register&gt;(SolrAddress);
                  _solr = ServiceLocator.Current.GetInstance&lt;ISolrOperations&lt;Register&gt;&gt;();
              }
              catch (Exception ex)
              {
                  throw new Exception(ex.Message);
              }
          }
  
      //Returns snippets from solr as BindingSource
      public BindingSource GetSnippets(string searchTerm, DateTime? startDate = null, DateTime? endDate = null)
      {
          ConnectToSolr();
  
          string dateQuery = startDate == null
                                 ? ""
                                 : endDate == null
                                       ? "savedate:\"" + convertDateToSolrFormat(startDate) + "\"" //only start date
                                       : "savedate:[" + convertDateToSolrFormat(startDate) + " TO " +
                                         convertDateToSolrFormat(endDate) + "]";//range between start and end date
  
          string textQuery = string.IsNullOrEmpty(searchTerm) ? "text:*" : "text:*" + searchTerm + "*";
          List&lt;Register&gt; list = new List&lt;Register&gt;();
          SolrQueryResults&lt;Register&gt; results;
          string currentId = "";
  
          try
          {
  
              results = _solr.Query(textQuery,
                  new QueryOptions
                  {
                      Highlight = new HighlightingParameters
                      {
                          Fields = new[] { "*" },
                      },
                      ExtraParams = new Dictionary&lt;string, string&gt;
                      {
                          {"fq", dateQuery},
                          {"sort", "savedate desc"}
                      }
                  });
  
              for (int i = 0; i &lt; results.Highlights.Count; i++)
              {
                  currentId = results[i].Id;
                  var h = results.Highlights[currentId];
                  if (h.Snippets.Count &gt; 0)
                  {
                      list.Add(new Register//here the error "the given key was not present in the dictionary pops up 
                      {   
                          Id = currentId, 
                          ContentLiteral = h.Snippets["content"].ToArray()[0].Trim(new[]{' ', '\n'}), 
                          SaveDateLiteral = results[i].SaveDate.ToShortDateString()
                      });
                  }
              }
  
              BindingList&lt;Register&gt; bindingList = new BindingList&lt;Register&gt;(list);                
              BindingSource bindingSource = new BindingSource();
              bindingSource.DataSource = bindingList;
              return bindingSource;
          }
          catch(Exception e)
          {
              MessageBox.Show(string.Format("{0}\nId:{1}", e.Message, currentId), "Solr error");
              return null;
          }            
      }
  </code></pre>