diff --git a/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs b/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs index a4836592845..5c4e005d95b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs +++ b/src/OrchardCore.Modules/OrchardCore.Autoroute/Indexes/AutoroutePartIndex.cs @@ -54,8 +54,8 @@ public class AutoroutePartIndex : MapIndex public class AutoroutePartIndexProvider : ContentHandlerBase, IIndexProvider, IScopedIndexProvider { private readonly IServiceProvider _serviceProvider; - private readonly HashSet _itemRemoved = new HashSet(); - private readonly HashSet _partRemoved = new HashSet(); + private readonly HashSet _itemRemoved = new(); + private readonly HashSet _partRemoved = new(); private IContentDefinitionManager _contentDefinitionManager; private IContentManager _contentManager; @@ -92,7 +92,7 @@ public override async Task PublishedAsync(PublishContentContext context) // Search for this part. var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType); - if (!contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart))) + if (contentTypeDefinition != null && !contentTypeDefinition.Parts.Any(ctpd => ctpd.Name == nameof(AutoroutePart))) { context.ContentItem.Remove(); _partRemoved.Add(context.ContentItem.ContentItemId); @@ -125,7 +125,7 @@ public void Describe(DescribeContext context) var partRemoved = _partRemoved.Contains(contentItem.ContentItemId); var part = contentItem.As(); - if (!partRemoved && (part == null || String.IsNullOrEmpty(part.Path))) + if (!partRemoved && String.IsNullOrEmpty(part?.Path)) { return null; }