{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L744-L780","documentation":"Multiple DbContext types match the given name case-insensitively, but none match case-sensitively. EF first does an OrdinalIgnoreCase pass; if that yields >1 it re-filters with Ordinal to disambiguate, and this error means the case-sensitive pass removed all of them. The fix is always to supply the exact casing of the intended type.","triggerScenarios":"Two contexts named e.g. 'AppDbContext' and 'AppdbContext' (or similar casing variants) coexist, and you pass a name whose casing matches neither exactly. FilterTypes OrdinalIgnoreCase -> count>1, then FilterTypes Ordinal -> count==0 -> throw MultipleContextsWithName.","commonSituations":"Renamed a context and the old one is still in a referenced assembly; case-only rename during a refactor; multiple contexts from third-party libraries whose names differ only in casing.","solutions":["Run 'dotnet ef dbcontext list' and pass the name with the exact casing shown.","If the duplicate is stale, rebuild/clean so the old type is no longer loaded.","Use the fully-qualified name (namespace + type) if casing alone is ambiguous."],"exampleFix":"// before\ndotnet ef migrations add Init --context appdbcontext\n// after\ndotnet ef migrations add Init --context AppDbContext","handlingStrategy":"validation","validationCode":"var matches = AppDomain.CurrentDomain.GetAssemblies()\n    .SelectMany(a => a.GetTypes())\n    .Where(t => typeof(DbContext).IsAssignableFrom(t) && !t.IsAbstract)\n    .Where(t => string.Equals(t.Name, contextName, StringComparison.Ordinal))\n    .ToList();\nif (matches.Count == 0) throw new ArgumentException(\"No exact-case match; fix casing.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never name two contexts differently only by case.","Pin context names to constants to avoid casing drift.","Use 'dotnet ef dbcontext list' output verbatim."],"tags":["efcore","dbcontext","cli","design-time","naming"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}