{"record":{"id":"d4709005c1d79e3a","repo":"dotnet/efcore","slug":"more-than-one-dbcontext-named-name-was-found-d47090","errorCode":null,"errorMessage":"More than one DbContext named '{name}' was found. Specify which one to use by providing its fully qualified name using its exact case.","messagePattern":"More than one DbContext named '(.+?)' was found\\. Specify which one to use by providing its fully qualified name using its exact case\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/DbContextOperations.cs","lineNumber":774,"sourceCode":"        }\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    }\n\n    private static Dictionary<Type, Func<DbContext>?> FilterTypes(\n        Dictionary<Type, Func<DbContext>?> types,\n        string name,\n        StringComparison comparisonType)\n        => types\n            .Where(t => string.Equals(t.Key.Name, name, comparisonType)\n                || string.Equals(t.Key.FullName, name, comparisonType)\n                || string.Equals(t.Key.AssemblyQualifiedName, name, comparisonType))\n            .ToDictionary();\n}\n","sourceCodeStart":756,"sourceCodeEnd":792,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L756-L792","documentation":"OperationException MultipleContextsWithQualifiedName thrown when both case-insensitive and exact-case filtering returned multiple matches, and none of those matches lives in the default (null) namespace. The supplied name is still ambiguous and must be made unique.","triggerScenarios":"Multiple contexts share the same fully-qualified-looking name across different namespaces, and none has no namespace. The final disambiguation step (select types with null namespace) yields nothing.","commonSituations":"Heavily nested module projects where contexts share short names across sub-namespaces; renaming/restructuring namespaces left duplicate short names.","solutions":["Supply a name that includes enough namespace prefix to select exactly one type.","Rename the colliding context classes to be globally unique.","Use `dotnet ef dbcontext list` output to copy the precise name."],"exampleFix":"# before - 'Models.AppDbContext' resolves to two types in different root namespaces\n> dotnet ef migrations add Init --context Models.AppDbContext\n\n# after\n> dotnet ef migrations add Init --context MyApp.Api.Models.AppDbContext","handlingStrategy":"validation","validationCode":"var cs = types.Where(t => t.Name.Equals(name, StringComparison.Ordinal)).ToList();\nif (cs.Count > 1 && cs.All(t => t.Namespace is not null))\n    throw new InvalidOperationException($\"'{name}' is still ambiguous; include the namespace.\");","typeGuard":null,"tryCatchPattern":"try { operations.CreateContext(name); }\ncatch (OperationException ex) when (ex.Message.Contains(\"fully qualified name using its exact case\"))\n{ /* extend the name with the full namespace prefix */ }","preventionTips":["Give each DbContext a globally unique fully-qualified name.","Run `dotnet ef dbcontext list` to see exact qualified names before scripting."],"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"}