Try our conversational search powered by Generative AI!

How do you use UnifiedSearch's ProjectImageUriFrom




I tried using this extension method to add a image thumbnail to my search results  as most of my pages have some sort of image, I used what '' suggested, and tried first this (in a init module depending on "IndexingModule"):

SearchClient.Instance.Conventions.UnifiedSearchRegistry.ForInstanceOf<ArticlePage>().ProjectImageUriFrom(a => a.ImageUri);

I also tried this:  

			            .CustomizeProjection(p => p.ProjectImageUriFrom<ArticlePage>(a => a.ImageUri));

I then reindexed and made a search like so:

EPiServer.Find.Framework.SearchClient.Instance.UnifiedSearchFor(query.Term, Language.Swedish).GetResult();

They both throw the error: "EPiServer.Find.ProjectionException: To deserialize objects the $type property must be set."

Could someone point me in the right direction as of how exactly I am supposed to use these projection extensions?

Oct 07, 2013 14:30

After some experimentation I notice that all other predefined projections (ex. title) works fine, it is only ImageUri that I cant get to work.

Oct 07, 2013 16:54


Try to use the OriginalString property:

  .CustomizeProjection(p => p.ProjectImageUriFrom<ArticlePage>(a => a.ImageUri.OriginalString));


Edited, Oct 08, 2013 9:24

That wouldnt even compile, the type must be a Uri, which lead me to believe there is some sort of json serialization error going on, but I have no idea what I can do to resolve it.

Edited, Oct 08, 2013 14:01

Ok, sorry, I'm using the EPiServer.Url as property type.

The implementation below works for me.

                    x => x.ProjectImageUriFrom<SitePageData>(
                        page => GetPageImage(page.PageImage.OriginalString)));

 private static Uri GetPageImage(string url)
                return null;

            return new Uri(url, UriKind.Relative);


Edited, Oct 09, 2013 9:18

Taht stopped me from getting exceptions atleast. But if I check the index, the 'SearchImageUri' property (or any like that) is not present anywhere for pages that do have a valid image set.

Oct 10, 2013 11:34

Hi guys,

I had the exact same Exception as Erik but I solved it in another way. My problem was that I couldn't project a thumbnail from an ImageVault image. I figured out that since the projection is executed on the searchresult the returned PageData is just a deserialized JSON-object, not a true PageData-object. And on that premiss I wrote this little crowbar implementation.

      x => x.ProjectImageUriFrom<PageData>(
         page => GetThumbnail(page.ContentGuid)));


private static Uri GetThumbnail(Guid id)
   if (id != null)
      PageData p = Utilities.GetPageFromGuid(id);
      if (p != null && (p[Web.Global.ImageProperties.List] != null ||
         p[Web.Global.ImageProperties.Media] != null))
         Thumbnail media = SiteDataFactory.Instance.GetThumbnail(p, 200, 140);
         if (media != null)
            return new Uri(media.Url, UriKind.RelativeOrAbsolute);
   return null;

Oct 24, 2013 17:49

Provided code examples don't work for me and ImageUri is always null if I use custom methods in ProjectImageUriFrom expression. The fix is to directly call "new Uri()" in the expression. This code worked for me:

	.IncludeField(x => x.SearchImageUri());

	.ProjectImageUriFrom(x => x.SearchImageUri() != null ? new Uri(x.SearchImageUri()) : null);

SearchImageUri is my extension method to get string url for page image and store it in Find index. It is fine to call it several times in ProjectImageUriFrom expression, because it's not really executed there, but used as a getter expression for "SearchImageUri" property of a search result.

Edited, May 19, 2016 19:31
* 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.