2

Recently migrated from Lucene to Solr search(7.2.1) in Sitecore.

When I try to get the search results from Code, I'm getting the exception

Non-static method requires a target

However, from Solr Admin, for the same index, I'm able to get the results in Query window.

Please help. enter image description here

4
  • Try changing the order of Select(s => s.GetItem()) and ToList(), so the line will be query.ToList().Select(s => s.GetItem()); – Marek Musielak Jul 2 '19 at 7:30
  • This confusing exception could be when "s" is null. Try filter it before selection: query.Where(x=>x != null).Select(s => s.GetItem()).ToList(); – Anton Jul 2 '19 at 9:35
  • Check your search logs to see what search is being executed and try executing exactly that search in your Solr Admin. Do you get the expected results? – Dan Sinclair Jul 2 '19 at 12:39
  • Did you were able to find the solution, I'm struggling with the same issue. – Gerardo Rodriguez Apr 13 at 16:58
0

This looks like an issue with your model class SiteBaseSearchEntity which is not defined as static.

Rob Ahnemann had the same issue with their model:

public class XConnectFormDataModel
    {
        public XdbModel Model { get; } = BuildModel();

        private static XdbModel BuildModel()
        {
            var builder = new XdbModelBuilder(nameof(XConnectFormDataModel), new XdbModelVersion(1, 0));
            builder.DefineFacet<Contact, FormDataFacet>(FormDataFacet.FacetKey);
      
      builder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            return builder.BuildModel();
    }
}

and the solution was to just add the static keyword in front of model:

public class XConnectFormDataModel
    {
        public **static** XdbModel Model { get; } = BuildModel();

        private static XdbModel BuildModel()
        {
            var builder = new XdbModelBuilder(nameof(XConnectFormDataModel), new XdbModelVersion(1, 0));
            builder.DefineFacet<Contact, FormDataFacet>(FormDataFacet.FacetKey);
      
      builder.ReferenceModel(Sitecore.XConnect.Collection.Model.CollectionModel.Model);
            return builder.BuildModel();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.