Epinova / Epinova.Elasticsearch

A search-plugin for Episerver CMS and Commerce
MIT License
29 stars 20 forks source link

Indexing XHtmlString-fields #124

Open baztaz1 opened 3 years ago

baztaz1 commented 3 years ago

EpiServer version: 11.16.0.0 Elastic Search Version: 7.6.1 Epinova.Elasticsearch Version: 11.7.1.105 Debug level: Debug

When running index job on XHtlmString-fields, we get following error: 2021-01-19 15:18:31,702 [14] ERROR Epinova.ElasticSearch.Core.EPiServer.Extensions.ContentExtensions: Failed to index custom property: ContentText System.InvalidCastException: Invalid cast from 'System.String' to 'EPiServer.Core.XhtmlString'. at System.Convert.DefaultToType(IConvertible value, Type targetType, IFormatProvider provider) at Epinova.ElasticSearch.Core.EPiServer.Extensions.ContentExtensions.AppendCustomProperties(IContent content, Type contentType, IDictionary`2 dictionary) in C:\projects\epinova-elasticsearch\src\Epinova.ElasticSearch.Core.EPiServer\Extensions\ContentExtensions.cs:line 352

We can fix it by adding following check on line 340:

if(property.Type.Name == "XhtmlString") { value = property.Getter.DynamicInvoke(content); } else { value = SerializeValue(property.Getter.DynamicInvoke(content)); }

Anyone else having this issue and know another workaround?