Sitemap does not work for the SXA sites when the enforce version presence feature is enabled


Description

When enabling the enforce version presence feature, a request to the sitemap.xml page in the multi-language SXA site might fail with the following error:

[NullReferenceException: Object reference not set to an instance of an object.]
Sitecore.XA.Feature.SiteMetadata.Sitemap.<GetItemsForOtherLanguages>d__29.MoveNext() +379
System.Collections.Generic.List`1.InsertRange(Int32 index, IEnumerable`1 collection) +525
Sitecore.XA.Feature.SiteMetadata.Sitemap.SitemapGenerator.ChildrenSearch(Item homeItem) +510
Sitecore.XA.Feature.SiteMetadata.Sitemap.SitemapGenerator.GenerateSitemap(Item homeItem, NameValueCollection externalSitemaps, SitemapLinkOptions sitemapLinkOptions) +206
Sitecore.XA.Feature.SiteMetadata.Pipelines.HttpRequestBegin.SitemapHandler.Process(HttpRequestArgs args) +707
(Object , Object ) +13
Sitecore.Pipelines.CorePipeline.Run(PipelineArgs args) +483
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain, Boolean failIfNotExists) +235
Sitecore.Pipelines.DefaultCorePipelineManager.Run(String pipelineName, PipelineArgs args, String pipelineDomain) +21
Sitecore.Web.RequestEventsHandler.OnPostAuthenticateRequest(HttpContextBase context) +213
Sitecore.Nexus.Web.HttpModule.’(Object “, EventArgs ”) +334
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +222
System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +212
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +90

Solution

To resolve the issue, consider one of the following options: