DefaultContentLoader.GetAncestors() throwing an exception

Vote:
 

Have a site running on CMS 12.29.0 and have the following exception thrown when trying to view one of the nodes in my content tree:

RequestPath: /EPiServer/shell/Stores/metadata/EPiServer.Core.ContentData

An unhandled exception has occurred while executing the request.

Exception: 
System.ArgumentNullException: Value cannot be null. (Parameter 'contentLink')
   at EPiServer.Core.Internal.DefaultContentLoader.GetAncestors(ContentReference contentLink)+MoveNext()
   at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
   at EPiServer.Cms.Shell.UI.ObjectEditing.EditorDescriptors.ContentReferenceListEditorDescriptor.GetUniqueRoots()+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at EPiServer.Cms.Shell.UI.ObjectEditing.EditorDescriptors.ContentReferenceListEditorDescriptor.ModifyMetadata(ExtendedMetadata metadata, IEnumerable`1 attributes)
   at EPiServer.Shell.ObjectEditing.ExtensibleMetadataProvider.ApplyExtendersToMetadata(ExtendedMetadata metadata, IEnumerable`1 attributes, IEnumerable`1 metadataHandlers)
   at EPiServer.Shell.ObjectEditing.ExtensibleMetadataProvider.GetExtendedMetadataForProperties(ExtendedMetadata parent, Object container, Type containerType, IMetadataProvider customProvider)
   at EPiServer.Shell.ObjectEditing.ExtendedMetadata.get_Properties()
   at EPiServer.Cms.Shell.UI.ObjectEditing.InternalMetadata.ReloadOnChangeMetadataExtender.ModifyMetadata(ExtendedMetadata metadata, IEnumerable`1 attributes)
   at EPiServer.Shell.ObjectEditing.ExtensibleMetadataProvider.ApplyExtendersToMetadata(ExtendedMetadata metadata, IEnumerable`1 attributes, IEnumerable`1 metadataHandlers)
   at EPiServer.Shell.ObjectEditing.ExtensibleMetadataProvider.GetExtendedMetadata(IEnumerable`1 attributes, Type containerType, Func`1 modelAccessor, Type modelType, String propertyName, String uiHint)
   at EPiServer.Shell.ObjectEditing.ExtensibleMetadataProvider.GetExtendedMetadataForType(Type modelType, Func`1 modelAccessor)
   at EPiServer.Shell.UI.Rest.MetadataStore.Get(String id, String modelAccessor)
   at lambda_method558(Closure , Object , Object[] )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.ResponseCaching.ResponseCachingMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Mediachase.Commerce.Anonymous.Internal.AnonymousIdMiddleware.Invoke(HttpContext httpContext)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
#322817
Edited, May 29, 2024 8:19
Vote:
 

It seems you might have a faulty root.

If you run this code, what root gives you the exception

            var roots = _contentRepositoryDescriptors.SelectMany(descriptor => descriptor.Roots).Distinct().ToList();
            var filteredRoots = new List<ContentReference>();
            foreach (var root in roots)
            {
                var ancestors = _contentLoader.GetAncestors(root);
                if (!ancestors.Any(ancestor => roots.Contains(ancestor.ContentLink)))
                {
                    filteredRoots.Add(root);
                }
            }
#322818
May 29, 2024 8:53
Vote:
 

The page that is throwing the exception is under the Root node, i.e. the "Home - Site Settings" node shown below:

I've tried a variation of your code (see below) to select the pages under the root, no exceptions were thrown.

			var subRoots = _contentRepository.GetChildren<PageData>(ContentReference.RootPage, LanguageSelector.MasterLanguage()).ToList();
			var filteredRoots = new List<ContentReference>();
			foreach (var root in subRoots)
			{
				var ancestors = _contentLoader.GetAncestors(root.ContentLink);
				if (!ancestors.Any(ancestor => subRoots.Contains(ancestor)))
				{
					filteredRoots.Add(root.ContentLink);
				}
			}
#322864
Edited, May 30, 2024 2:11
Vote:
 

I think i've found part of the issue; reinitializing that node has made the dotnet exception go away.

#322866
Edited, May 30, 2024 3:47
* 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.