{"record":{"id":"dd6ab064ce2d39ea","repo":"dotnet/efcore","slug":"the-exception-list-configured-for-cosmos-automatic","errorCode":null,"errorMessage":"The exception list configured for Cosmos automatic indexing on container '{container}' differs between entity types '{entityType1}' and '{entityType2}'. All entity types mapped to the same container must agree on the automatic-indexing exception list.","messagePattern":"The exception list configured for Cosmos automatic indexing on container '(.+?)' differs between entity types '(.+?)' and '(.+?)'\\. All entity types mapped to the same container must agree on the automatic-indexing exception list\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs","lineNumber":371,"sourceCode":"                    // an explicit 'true' when comparing across entity types in the same container.\n                    if ((currentEnabled ?? true) != (automaticIndexingEnabled ?? true))\n                    {\n                        throw new InvalidOperationException(\n                            CosmosStrings.InconsistentAutomaticIndexingEnabled(\n                                container,\n                                automaticIndexingOwner.DisplayName(),\n                                entityType.DisplayName()));\n                    }\n\n                    // Exceptions only affect the indexing policy when automatic indexing is enabled, so don't compare\n                    // them when it is disabled.\n                    if ((automaticIndexingEnabled ?? true)\n                        && ((currentExceptions is null) != (automaticIndexingExceptions is null)\n                            || (currentExceptions is not null\n                                && automaticIndexingExceptions is not null\n                                && !currentExceptions.SequenceEqual(automaticIndexingExceptions, StringComparer.Ordinal))))\n                    {\n                        throw new InvalidOperationException(\n                            CosmosStrings.InconsistentAutomaticIndexing(\n                                container,\n                                automaticIndexingOwner.DisplayName(),\n                                entityType.DisplayName()));\n                    }\n                }\n            }\n\n            // Walk the full owned/complex tree to surface every HasIndex declared in this container.\n            // Vector and full-text indexes are allowed to traverse owned types; only regular indexes are\n            // rejected\n            foreach (var (declaringEntityType, index) in EnumerateContainerIndexes(entityType))\n            {\n                if (!declaringEntityType.IsDocumentRoot()\n                    && index.GetVectorIndexType() == null\n                    && index.IsFullTextIndex() != true)\n                {\n                    throw new InvalidOperationException(","sourceCodeStart":353,"sourceCodeEnd":389,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L353-L389","documentation":"Thrown when the exception list for Cosmos automatic indexing differs between two entity types in the same container. The validator only compares exception lists when automatic indexing is enabled (since exceptions have no effect when indexing is off); it treats a null list as distinct from a non-null list and compares non-null lists with an ordinal SequenceEqual. All types sharing a container must declare the same exception list.","triggerScenarios":"Two document-root entity types in the same container both enable automatic indexing but pass different paths to HasAutomaticIndexingExceptions, or one passes a list while the other passes none. Fires during model validation.","commonSituations":"Adding an excluded path to one root entity type and forgetting the others in the shared container; ordering differences in the exception list (compared with StringComparer.Ordinal, so order matters); refactoring JSON property paths that left stale exceptions on some types.","solutions":["Collect every JSON path that must be excluded from indexing and pass the exact same list (same items, same order) to HasAutomaticIndexingExceptions on every document-root entity in the container.","Centralize the exception list in a shared readonly field/property so all configs reference one source of truth.","Remove partial HasAutomaticIndexingExceptions calls; either every root has the same list or none does."],"exampleFix":"// before\nmodelBuilder.Entity<Invoice>().ToContainer(\"Docs\")\n    .HasAutomaticIndexing(true)\n    .HasAutomaticIndexingExceptions(\"/Transient/*\");\nmodelBuilder.Entity<Receipt>().ToContainer(\"Docs\")\n    .HasAutomaticIndexing(true)\n    .HasAutomaticIndexingExceptions(\"/Cache/*\");\n\n// after\nstatic readonly string[] Excluded = { \"/Transient/*\", \"/Cache/*\" };\nmodelBuilder.Entity<Invoice>().ToContainer(\"Docs\")\n    .HasAutomaticIndexing(true).HasAutomaticIndexingExceptions(Excluded);\nmodelBuilder.Entity<Receipt>().ToContainer(\"Docs\")\n    .HasAutomaticIndexing(true).HasAutomaticIndexingExceptions(Excluded);","handlingStrategy":"validation","validationCode":"foreach (var g in dbContext.Model.GetEntityTypes().GroupBy(e => e.GetContainer()))\n{\n    IReadOnlyList<string>? first = null;\n    foreach (var e in g.Where(et => et.BaseType is null))\n    {\n        var ex = e.FindAnnotation(CosmosAnnotationNames.AutomaticIndexingExceptions)?.Value as IReadOnlyList<string>;\n        if (ex is null) continue;\n        if (first is null) first = ex;\n        else if (!first.SequenceEqual(ex, StringComparer.Ordinal))\n            throw new InvalidOperationException($\"Exception list mismatch on {g.Key}\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Share a single readonly exception-list instance across all root entities of a container.","Keep list ordering stable (validator uses ordinal SequenceEqual).","Add a model-validation test in CI."],"tags":["cosmos","model-validation","indexing","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}