IPublishedContent's Root() method doesn't return t...
# help-with-umbraco
r
I don't know if it is a bug or somethings has changed in Umbraco 15. I am working on some indexing/examine code. I receive a IPublishedContent item which can be Content or Media. When it is content calling .Root() returns me the top ancestor as it should but for some reason when it is a Media it just returns the same item. Any idea what is going on?
l
Could you share your code that you’re running for this?
r
sure. I am working on a search implementation for my company. this code is just a piece of it. the usage of .Root() comes at line 93 where I call
SearchConfiguration? searchConfiguration = _siteConfigurationProvider.GetSearchConfigurationByContent(content);
https://cdn.discordapp.com/attachments/1334798793601847296/1334803960678322267/StoreComputedFieldsValuesInIndex.cs?ex=679ddc8f&is=679c8b0f&hm=ebd2146586c64f54dd47fbc0efb12ef87f5f5d51ce9e7ab454c592dffd98c977&
the above code just bring some context (in case it is important. the exact call to .Root() happens here
Copy code
public SiteConfiguration GetByContent(IPublishedContent content)
 {
     ArgumentNullException.ThrowIfNull(content);

     switch (content.ContentType.ItemType)
     {
         case PublishedItemType.Content:
             {
                 return GetByContentRootAlias(content.Root().ContentType.Alias);
             }
         case PublishedItemType.Media:
             {
                 return GetByMediaRootKey(content.Root().Key); // returns wrong Key and I cannot get my proper SiteConfiguration because I rely on the Root key here
             }

         case PublishedItemType.Unknown:
         case PublishedItemType.Element:
         case PublishedItemType.Member:
         default:
             {
                 throw new SiteConfigurationException($"SiteSearchConfiguration cannot be found by '{content.ContentType.ItemType}' content type");
             }
     }
 }
5 Views