The given key was not present in the dictionary.
My project has a custom search page that gets search results using the Sitecore search API. The out of the box Coveo search page works fine but the custom search page gives me the error "The given key was not present in the dictionary."
To get results I'm using the Sitecore PredicateBuilder class to get a list of Sitecore SearchResultItems. The error occurs when I try to use SearchResultItem.GetItem() to get a Sitecore item. I've had trouble in the past where the query is actually the problem, and the error only appears when I try to read the result. This doesn't seem to be the case, since I am able to use functions like .Count(), so I am getting a countable number of search result items that are causing errors when I try to get the Sitecore item from them. Also, I get the error even when the predicate builder is just the default true value, so the predicate doesn't seem to be the issue.
I noticed this problem after updating my Coveo version. The code works on Coveo for Sitecore revision 742 (the October release) but breaks on revision 863 (December). I'm not sure which one is the anomaly, or how to fix it. Has anyone experienced this before?
I think your code throws the exception when calling
Item result = returned.GetItem();
SearchResultItem.GetItem() method seems to only use the
this["_uniqueid"] field accessor and the
Uri property (that is populated when the
_uniqueid field is returned on the document).
You specified that the
Uri property of the results was null. This is probably related to the inability to find the
_uniqueid field in the
this fields dictionary leading to your exception.
It seems that the
_uniqueid field is not returned in the results.
One possible reason is customization done in the
<coveoQueryFieldPipeline> element of the
Coveo.SearchProvider.config file (see Optimizing LINQ Query Performance). Can you provide me your
<coveoQueryFieldPipeline> element please?
You can also check in the Coveo Administration Tool Index Browser to see if all the documents of your instance's Coveo_web_index source contains the @fz95xuniqueidXXXXX field and that it contains a value.