{"record":{"id":"06bf8bd23107ee41","repo":"dotnet/efcore","slug":"more-than-one-dbcontext-named-name-was-found","errorCode":null,"errorMessage":"More than one DbContext named '{name}' was found. Specify which one to use by providing its fully qualified name.","messagePattern":"More than one DbContext named '(.+?)' was found\\. Specify which one to use by providing its fully qualified name\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/DbContextOperations.cs","lineNumber":762,"sourceCode":"    {\n        var candidates = FilterTypes(types, name, StringComparison.OrdinalIgnoreCase);\n        if (candidates.Count == 0)\n        {\n            return throwOnEmpty\n                ? throw new OperationException(DesignStrings.NoContextWithName(name))\n                : candidates;\n        }\n\n        if (candidates.Count == 1)\n        {\n            return candidates;\n        }\n\n        // Disambiguate using case\n        candidates = FilterTypes(candidates, name, StringComparison.Ordinal);\n        if (candidates.Count == 0)\n        {\n            throw new OperationException(DesignStrings.MultipleContextsWithName(name));\n        }\n\n        if (candidates.Count == 1)\n        {\n            return candidates;\n        }\n\n        // Allow selecting types in the default namespace\n        candidates = candidates.Where(t => t.Key.Namespace == null).ToDictionary();\n        if (candidates.Count == 0)\n        {\n            throw new OperationException(DesignStrings.MultipleContextsWithQualifiedName(name));\n        }\n\n        Check.DebugAssert(candidates.Count == 1, $\"candidates.Count is {candidates.Count}\");\n\n        return candidates;\n    }","sourceCodeStart":744,"sourceCodeEnd":780,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L744-L780","documentation":"OperationException MultipleContextsWithName thrown when the name matched multiple contexts case-insensitively, then re-filtering with Ordinal (exact case) matched none. The user must supply a fully qualified name to disambiguate.","triggerScenarios":"Two contexts whose short/type names differ only in case across namespaces (e.g. Foo.Context vs Bar.context), or several contexts that share the same short name in different namespaces and the supplied name is the short one.","commonSituations":"Naming collisions after merging projects/modules, or accidental duplicate class names in separate namespaces.","solutions":["Pass the fully-qualified type name including its namespace: --context MyApp.Data.AppDbContext.","Rename one of the colliding context types to remove the ambiguity.","List contexts with `dotnet ef dbcontext list` to see the exact qualified names."],"exampleFix":"# before - 'AppDbContext' exists in two namespaces, no exact-case match\n> dotnet ef migrations add Init --context AppDbContext\n\n# after\n> dotnet ef migrations add Init --context MyApp.Data.AppDbContext","handlingStrategy":"validation","validationCode":"var ci = types.Where(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).ToList();\nvar cs = types.Where(t => t.Name.Equals(name, StringComparison.Ordinal)).ToList();\nif (ci.Count > 1 && cs.Count == 0)\n    throw new InvalidOperationException($\"Name '{name}' matches multiple contexts only case-insensitively; use the fully-qualified name.\");","typeGuard":null,"tryCatchPattern":"try { operations.CreateContext(name); }\ncatch (OperationException ex) when (ex.Message.Contains(\"More than one DbContext named\"))\n{ /* supply the fully-qualified type name */ }","preventionTips":["Use fully-qualified type names when contexts share short names.","Avoid creating context classes with names differing only by case."],"tags":["design-time","ef-tools","context-discovery","ambiguous","namespace"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}