{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L756-L792","documentation":"Multiple DbContext types share the exact same Name (case-sensitive) and live in different namespaces, and none of them has a null namespace, so EF cannot pick one. Even the fully-qualified-name match was ambiguous. You must identify the context by its exact fully qualified (or assembly-qualified) name.","triggerScenarios":"Two types literally named 'AppDbContext' in namespaces A and B both pass the Ordinal filter (count>1), and the null-namespace tiebreaker at line 771 also yields >1 (or 0, triggering this throw). Reached only when short name + casing both match multiple types.","commonSituations":"Two projects in the same solution each define MyApp.AppDbContext; a duplicated context copied across folders; linking the same context under different namespaces via internals-visible-to tricks.","solutions":["Pass the fully qualified name: --context MyNamespace.AppDbContext.","If still ambiguous, pass the AssemblyQualifiedName (use 'dotnet ef dbcontext list --json' to see full names).","Rename one of the colliding types so they are unambiguous.","Remove a stale project reference that brings in the duplicate."],"exampleFix":"// before\ndotnet ef migrations add Init --context AppDbContext\n// after\ndotnet ef migrations add Init --context Inventory.AppDbContext","handlingStrategy":"validation","validationCode":"var candidates = AppDomain.CurrentDomain.GetAssemblies()\n    .SelectMany(a => a.GetTypes())\n    .Where(t => typeof(DbContext).IsAssignableFrom(t) && !t.IsAbstract && t.Name == contextName)\n    .ToList();\nif (candidates.Count > 1)\n    contextName = candidates.Single(t => t.Namespace == wantedNamespace).FullName;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always reference contexts by FullName in scripts.","Avoid duplicate short names across namespaces.","Document the canonical context name in the project README."],"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"}