Search issue with .NET Client API

Vote:
 

Hey! We're working on updating one of our applications that serves as a Find indexing job (we use it to populate our index with data). The application was running on .NET Framework 4.8 and referenced EPiServer.Find 13.3.0. We are upgrading to .NET 8 and now referencing EPiServer.Find 16.2.0. The project is a console application.

We're running into an issue when performing a search with the EPiServer Find Client class.

When running the following code:

Client.Search<LocationPage>()
                    .OrFilter(x => x.LocationPageStyle.Match((int)Global.LocationPageType.RobustLocation))
                    .OrFilter(x => x.LocationPageStyle.Match((int)Global.LocationPageType.SimpleLocation))
                    .Select(x => new LocationPageData() { AddressKey = x.AddressKey, PageUrl = ((ISearchContent)x).SearchHitUrl, WaitTimeId = x.WaitTimeID })
                    .Skip(skip)
                    .Take(take)
                    .GetResult();

We receive the following error:

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=EPiServer.Find
  StackTrace:
   at EPiServer.Find.LambdaExpressionExtensions.CachedCompile(LambdaExpression expression, Object[]& constants)
   at EPiServer.Find.LambdaExpressionExtensions.CachedCompileInvoke(Expression expression)
   at EPiServer.Find.FilterExpressionParser.GetFilterFromDelegateFilterBuilderMethod(MethodCallExpression methodExpression, String fieldName)
   at EPiServer.Find.FilterExpressionParser.<GetFilter>b__2_1[TSource](MethodCallExpression x)
   at EPiServer.Find.Helpers.Linq.ExpressionReplacer`1.Visit(Expression expression)
   at EPiServer.Find.Helpers.Linq.ExpressionReplacer`1.Replace(Expression expression, Func`2 predicate, Func`2 replaceWith)
   at EPiServer.Find.Helpers.Linq.ExpressionExtensions.Replace[TExpression](Expression expression, Func`2 predicate, Func`2 replaceWith)
   at EPiServer.Find.FilterExpressionParser.GetFilter[TSource](Expression`1 filterExpression)
   at EPiServer.Find.FilterExpression`1.ParseFilterExpression[TSource](ITypeSearch`1 search, Expression`1 filterExpression)
   at EPiServer.Find.TypeSearchExtensions.OrFilter[TSource](ITypeSearch`1 search, Expression`1 filterExpression)
   at OhioHealthImport.Program.Main(String[] args) in C:\source\find-indexing-job\CHCDataImport\CHCDataImport\Program.cs:line 61

And when we try the following:

Client.Search<LocationPage>()
                .GetResult();

We receive:

Newtonsoft.Json.JsonSerializationException
  HResult=0x80131500
  Message=Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'EPiServer.Find.Cms.IndexableContentReference' because the type requires a JSON string value to deserialize correctly.
To fix this error either change the JSON to a JSON string value or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'hits.hits[0]._source.HeaderImage.$type', line 1, position 374.
  Source=Newtonsoft.Json
  StackTrace:
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at EPiServer.Find.Api.SearchHitConverter.PopulateItemProperty(JsonReader reader, JsonSerializer serializer, Type objectType, Object item)
   at EPiServer.Find.Api.SearchHitConverter.PopulateProperty(JsonReader reader, JsonSerializer serializer, Type objectType, String propertyName, Object item)
   at EPiServer.Find.Json.IgnoredPropertiesHandlingConverterBase.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateList(IList list, JsonReader reader, JsonArrayContract contract, JsonProperty containerProperty, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateList(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, Object existingValue, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
   at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Deserialize[T](JsonReader reader)
   at EPiServer.Find.Api.Command.GetResponse[TResult](IJsonRequest request)
   at EPiServer.Find.Api.SearchCommand`1.Execute()
   at EPiServer.Find.Client.Search[TResult](SearchRequestBody requestBody, Action`1 commandAction)
   at EPiServer.Find.SearchExtensions.GetResult[TResult](ISearch`1 search)
   at OhioHealthImport.Program.Main(String[] args) in C:\source\find-indexing-job\CHCDataImport\CHCDataImport\Program.cs:line 61

It seems that, when our object is indexed, the value for the HeaderImage property of type ContentReference is serialized into a JSON object as opposed to a JSON string. When we try to retrieve the object from the index and deserialize it, it throws the above error.

This was working just fine before we upgraded from Find 13.3.0.

Any idea as to why this is suddenly a problem, and whether or not there's a way around it? Appreciate any and all help!

#324902
Edited, Jul 03, 2024 23:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.