Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Chris Mahoney 235 posts 447 karma points
    Dec 13, 2023 @ 21:28
    Chris Mahoney
    0

    Site Map crashing after 10.8.2 upgrade

    Hi everyone,

    I've just upgraded my site from Umbraco 10.7 to 10.8.2 and everything's working correctly, except for my Site Map page. When I open it, I get the following error:

    The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source.

    void Traverse(IPublishedContent? node)

    My .cshtml file is as follows. As you can see, this is similar to the snippet provided with Umbraco:

    @inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage
    @using Umbraco.Cms.Core
    @using Umbraco.Cms.Core.Models.PublishedContent
    @using Umbraco.Cms.Core.Routing
    @using Umbraco.Extensions
    
    @inject IPublishedValueFallback PublishedValueFallback
    @inject IPublishedUrlProvider PublishedUrlProvider
    @*
        This snippet makes a list of links of all visible pages of the site, as nested unordered HTML lists.
    
        How it works:
        - It uses a local method called Traverse() to select and display the markup and links.
    *@
    
    @{
        var selection = Model.Root();
    }
    
    <div class="sitemap">
        @* Render the sitemap by passing the root node to the traverse method, below *@
        @{
            Traverse(selection);
        }
    </div>
    
    @* Helper method to traverse through all descendants *@
    @{
        void Traverse(IPublishedContent? node)
        {
            //Update the level to reflect how deep you want the sitemap to go
            var maxLevelForSitemap = 5;
    
            @* Select visible children *@
            var selection = node?.Children.Where(x => x.IsVisible(PublishedValueFallback) && x.Level <= maxLevelForSitemap).ToArray();
    
            @* If any items are returned, render a list *@
            if (selection?.Length > 0)
            {
                <ul class="sitemap">
                    @foreach (var item in selection)
                    {
                        <li class="[email protected]">
                            <a href="@(item.IsDocumentType("Faq") ? (item.Level == 4 ? item.Parent.Url(PublishedUrlProvider) + "#a" + item.Id : item.Parent.Parent.Url(PublishedUrlProvider) + "#a" + item.Id) : item.Url(PublishedUrlProvider))">@item.Name</a>
    
                            @* Run the traverse helper again for any child pages *@
                            @if (!item.IsDocumentType("BusRoute"))
                            {
                                Traverse(item);
                            }
                        </li>
                    }
                </ul>
            }
        }
    }
    

    I've tried putting #nullable enable before the Traverse method (and also right at the start of the file), but it doesn't help. I also have <Nullable>enable</Nullable> in my .csproj file.

    Does anyone have any idea what's going on here? It worked fine under 10.7 and I don't see any breaking changes in 10.8 that could explain this. Help! :)

  • Chris Mahoney 235 posts 447 karma points
    Jan 08, 2024 @ 20:33
    Chris Mahoney
    0

    I'm getting the same error with 10.8.3. Any ideas?

  • Chris Mahoney 235 posts 447 karma points
    25 days ago
    Chris Mahoney
    0

    Just for some closure...

    It works if I remove the "?" from the Traverse method, i.e.

    void Traverse(IPublishedContent node)

    I can't imagine that this would cause any issues, as it should only ever try to traverse into content that already exists. It's still a mystery as to why it's failing in the first place, as the same code works fine on other sites.

Please Sign in or register to post replies

Write your reply to:

Draft