SaaS CMS has officially launched! Learn more now.

XhtmlString deserialization issue



I am having an issue when calling GetResult from the search query, the XhtmlString element always return null. I have checked data in the Explorer, it's there. 

"Description": {
        "$type": "EPiServer.Core.XhtmlString, EPiServer",
        "AsViewedByAnonymous$$string": "Size: Bath Towel - 70 x 140cm Hand - 45 x 65cm Bath Sheet - 80 x 160cm GSM: 550",
        "___types": [
            "EPiServer.Data.Entity.IReadOnly`1[[EPiServer.Core.XhtmlString, EPiServer, Version=, Culture=neutral, PublicKeyToken=8fe83dea738b45b7]]",
        "IsEmpty$$bool": false,
        "IsModified$$bool": false

I am using the latest EPi find (v11) with EPiCommerce 9.6
Feb 04, 2016 11:49


Are you using .AsViewedByAnonymous?

Could you post your query?

Feb 04, 2016 12:20
public class FindProduct
        public string IndexId { get; set; }
        public string Code { get; set; }
        public int Id { get; set; }
        public string DisplayName { get; set; }
        public string Language { get; set; }

        public string DefaultImageUrl { get; set; }

        public XhtmlString Description { get; set; }
        public SearchResults<FindProduct> SearchProductsByStyle(ProductBase productBase, bool selfIncluded = false)
            var query = SearchClient.Instance.Search<FindProduct>()
                .Filter(x => x.StyleCode.Exists())
                .Filter(x => x.StyleCode.MatchCaseInsensitive(productBase.StyleCode))
                .Filter(x => x.Language.Exists())
                .Filter(x => x.Language.MatchCaseInsensitive(productBase.Language.Name));

            if (!selfIncluded)
                    .Filter(x => x.Code.Exists())
                    .Filter(x => !x.Code.Match(productBase.Code));
            return query.GetResult();
Feb 04, 2016 12:26

For the time being, I have to change my poco object "Description" type to string, and convert xhtmlstring to html encoded string before assign to description. 

EPi find seems not working well with complex object  :p

Feb 04, 2016 13:21

XhtmlString is a complex property type, which is usually fetched when using GetContentResult - which fetches the content from the database.
If possible, I would suggest you change your property type to a string.

By the way, I don't think you need all those .Exists filters. The Match/MatchCaseInsensitive will take care of that anyway - even if the value is null.

Feb 04, 2016 13:25

Hi Per

Thanks for your prompt reply and code review :)

As I said, I had switched to string already. Are there any other speicial complex types not supported by EPi find?

Feb 04, 2016 13:38

Well, the XhtmlString is a bit special, as it is built up by fragments. Some of these might not be visible to certain users and some might be references to blocks or media data. Because of this the value that resides in the Find index is a simple serialized value, and the common usage would be to either project the value using .Select or to fetch the content using GetContentResult.

As for other types... I suppose you would get the same problem had you added a property of type ContentArea to your poco object

Feb 04, 2016 13:44
* 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.