{"record":{"id":"d939fca00dc0a9d2","repo":"dotnet/efcore","slug":"no-dbcontext-named-name-was-found","errorCode":null,"errorMessage":"No DbContext named '{name}' was found.","messagePattern":"No DbContext named '(.+?)' was found\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/DbContextOperations.cs","lineNumber":749,"sourceCode":"            ? types.First()\n            : types.Count switch\n            {\n                0 => throw new OperationException(DesignStrings.NoContext(_assembly.GetName().Name)),\n                1 => types.First(),\n                _ => throw new OperationException(DesignStrings.MultipleContexts)\n            };\n    }\n\n    private Dictionary<Type, Func<DbContext>?> FilterTypes(\n        Dictionary<Type, Func<DbContext>?> types,\n        string name,\n        bool throwOnEmpty)\n    {\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;","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L731-L767","documentation":"OperationException NoContextWithName thrown when a name was supplied but FilterTypes (case-insensitive) matched zero contexts. The user asked for a context that does not exist in the assembly.","triggerScenarios":"Passing --context with a typo, wrong case is fine (case-insensitive match attempted), but a name that matches no context type at all. Also when throwOnEmpty is true after filtering.","commonSituations":"Renamed context class, wrong namespace prefix used, copy-pasted command from another project, or pointing the tools at the wrong assembly.","solutions":["List available contexts: `dotnet ef dbcontext list` and use the exact name shown.","Run from the correct startup/project assembly.","Use the fully-qualified type name to be unambiguous.","Check for typos and case (case-insensitive but spelling must match)."],"exampleFix":"# before\n> dotnet ef migrations add Init --context AppDbCtxt   # typo\n\n# after\n> dotnet ef dbcontext list\n> dotnet ef migrations add Init --context MyApp.Data.AppDbContext","handlingStrategy":"validation","validationCode":"var matches = operations.GetContextTypes().Where(t => t.Name.Equals(name, StringComparison.OrdinalIgnoreCase)).ToList();\nif (matches.Count == 0)\n    throw new InvalidOperationException($\"No context named '{name}'; run 'dotnet ef dbcontext list'.\");","typeGuard":null,"tryCatchPattern":"try { operations.CreateContext(name); }\ncatch (OperationException ex) when (ex.Message.Contains(\"No DbContext named\"))\n{ /* list contexts and use the exact name */ }","preventionTips":["Use `dotnet ef dbcontext list` to copy exact names.","Prefer fully-qualified names in CI scripts."],"tags":["design-time","ef-tools","context-discovery","not-found"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}