{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Infrastructure/Internal/CosmosModelValidator.cs#L353-L389","documentation":"Thrown by ValidateContainerIndexing when two document-root entity types in the same container agree that automatic indexing is enabled but their exception (excluded-path) lists differ. The validator compares the AutomaticIndexingExceptions lists for null-ness and element-wise equality (ordinal); only compared when automatic indexing is enabled.","triggerScenarios":"Calling .HasAutomaticIndexing(true).Except(\"/a/*\") on one root and .HasAutomaticIndexing(true).Except(\"/b/*\") (or no Except) on another root mapped to the same container.","commonSituations":"Per-entity tuning of excluded write paths without realizing the exclusion list is container-wide; incrementally adding exclusions on new entities; refactoring an entity into a shared container with a different exclusion set.","solutions":["Make the excluded-path list identical (same set, same order) on every root entity in the container.","Consolidate automatic-indexing configuration onto one root entity and remove it from the others.","Centralize the exception list in a constant and apply it uniformly."],"exampleFix":"// before\nmodelBuilder.Entity<A>().ToContainer(\"shared\").HasAutomaticIndexing(true).Except(\"/temp/*\");\nmodelBuilder.Entity<B>().ToContainer(\"shared\").HasAutomaticIndexing(true).Except(\"/cache/*\");\n\n// after\nstring[] excluded = [\"/temp/*\", \"/cache/*\"];\nvar aBuilder = modelBuilder.Entity<A>().ToContainer(\"shared\").HasAutomaticIndexing(true);\nforeach (var p in excluded) aBuilder.Except(p);\nvar bBuilder = modelBuilder.Entity<B>().ToContainer(\"shared\").HasAutomaticIndexing(true);\nforeach (var p in excluded) bBuilder.Except(p);","handlingStrategy":"validation","validationCode":"using var ctx = new MyContext();\nforeach (var grp in ctx.Model.GetEntityTypes()\n    .Where(e => e.FindPrimaryKey() != null && e.GetContainer() != null && e.BaseType == null)\n    .GroupBy(e => e.GetContainer()))\n{\n    var lists = grp.Select(e => (e.GetAutomaticIndexingEnabled() ?? true)\n        ? (e.GetAutomaticIndexingExceptions() ?? Array.Empty<string>()).OrderBy(s => s).ToArray()\n        : Array.Empty<string>())\n        .Select(a => string.Join(\",\", a)).Distinct().ToList();\n    Debug.Assert(lists.Count <= 1, $\"Container {grp.Key} has differing exception lists\");\n}","typeGuard":null,"tryCatchPattern":"try { ctx.Model.GetModel(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"exception list configured for Cosmos automatic indexing\"))\n{\n    logger.LogError(ex, \"Automatic-indexing exception list mismatch in shared container\");\n    throw;\n}","preventionTips":["Keep the excluded-paths list in a shared constant applied to every root in the container.","Order the list deterministically; compare in tests.","Document that exception lists are container-wide, not per-entity."],"tags":["cosmos","configuration","model-validation","indexing","shared-container"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}