umbraco / Umbraco.Headless.Client.Net

.NET Client Library and Samples for the Umbraco headless cms Cloud Service called Umbraco Heartcore
https://umbraco.com/products/umbraco-heartcore/
13 stars 14 forks source link

GetAncestors(Guid id, string culture = null) throws NullReferenceException on when I try to get the ancestors of a level 1 node #30

Closed miguelcrpinto closed 3 years ago

miguelcrpinto commented 4 years ago

Whenever I try to use the to get a node ancestors of a level 1 node by Id and culture (without specifying the content type) I get a NullReferenceException.

Stack trace: at Umbraco.Headless.Client.Net.Delivery.ContentDelivery.d__13.MoveNext()

I know that level 1 nodes do not have ancestors but I believe this method should then just return an empty IEnumerable.

jfm5248 commented 4 years ago

I was just troubleshooting this myself. The null reference exception happens because the client code attempts to reference root.Content.Items, but root is null if there are no ancestors for the ID you've provided.

Line 106 in Umbraco.Headless.Client.Net.Delivery.ContentDelivery:

        public async Task<IEnumerable<Content>> GetAncestors(Guid id, string culture)
        {
            var service = RestService.For<ContentDeliveryEndpoints>(_httpClient);
            var root = await service.GetAncestors(_configuration.ProjectAlias, culture, id).ConfigureAwait(false);
            return root.Content.Items;
        }
sitereactor commented 4 years ago

Alright, thanks for posting this and the code in question. Looks like an easy fix 👍

umbrabot commented 3 years ago

Hiya @miguelcrpinto,

Just wanted to let you know that we noticed that this issue got a bit stale and might not be relevant any more.

We will close this issue for now but we're happy to open it up again if you think it's still relevant (for example: it's a feature request that's not yet implemented, or it's a bug that's not yet been fixed).

To open it this issue up again, you can write @umbrabot still relevant in a new comment as the first line. It would be super helpful for us if on the next line you could let us know why you think it's still relevant.

For example:

@umbrabot still relevant This bug can still be reproduced in version x.y.z

This will reopen the issue in the next few hours.

Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face: