hit.OriginalObjectGetter.Invoke() is null (Find 13.2.2)

Vote:
 

We have upgraded to 13.2.2 and some code based on episerver posts that was working fine has broken.

This below was getting back the underlying type from UnifiedSearch, anyone have any idea how to fix without reloading the content.

        /// <summary>
        /// Gets the original object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="hit">The hit.</param>
        /// <returns>T.</returns>
        public static T GetOriginalObject<T>(this UnifiedSearchHit hit)
        {
            if (hit.OriginalObjectGetter != null)
            {
                var original = hit.OriginalObjectGetter.Invoke();

                if (original is T)
                {
                    return (T)original;
                }
            }

            return default(T);
        }
#206867
Sep 02, 2019 17:03
Vote:
 

Which version did you upgrade from? It might be not different, but you probably want to call it as hit.OriginalObjectGetter() 

#206871
Sep 02, 2019 20:27
Vote:
 

I also use this approach a lot:

var originalType = searchHit.OriginalObjectGetter.Invoke() as MyPreciousType;

It is working as expected in version 13.0.5.

#206872
Sep 02, 2019 20:49
Vote:
 

Thanks guys, at the time of writing this the code was erroring out due to a null coming back. I had a thought that it might be something dodgy with a single record in Find from the upgrade possibly so I've added some proper null handling (which should of been there from the start) and there's a lot of results coming back now. At least this means this method is working.

#206878
Sep 03, 2019 9:17