SaaS CMS has officially launched! Learn more now.

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


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);
Sep 02, 2019 17:03

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

Sep 02, 2019 20:27

I also use this approach a lot:

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

It is working as expected in version 13.0.5.

Sep 02, 2019 20:49

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.

Sep 03, 2019 9:17
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.