{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L731-L767","documentation":"Thrown by FilterTypes when a context name was passed to a command (--context) but no DbContext type in the assembly matches that name, even case-insensitively. It comes from DbContextOperations.CreateContext, which is the single funnel used by every dotnet ef / PMC command that needs a DbContext. The error surfaces only when throwOnEmpty is true; otherwise the method returns an empty set and a later 'no context' error fires.","triggerScenarios":"Calling dotnet ef migrations add --context WrongName, or Database.GetMigrations/--context with a typo'd context name. CreateContext(name) -> FilterTypes(types, name, throwOnEmpty:true) finds zero candidates because none of t.Key.Name/FullName/AssemblyQualifiedName equal 'name' (OrdinalIgnoreCase) and throwOnEmpty is true.","commonSituations":"Typo in the context name; context lives in a different assembly than the one being scanned (wrong --startup-project/--project); context is nested/generic and its Name doesn't match what you typed; the assembly referenced is a stale build that predates the context being added.","solutions":["List contexts first: run 'dotnet ef dbcontext list' and copy the exact name shown.","If none appear, fix the project being scanned -- pass --project <project-with-context> and --startup-project <startup-project>.","Rebuild the startup project so the freshly compiled assembly containing the DbContext is loaded.","If the context is generic or abstract, make it concrete or reference the concrete subclass."],"exampleFix":"// before\ndotnet ef migrations add Init --context AppDbcontext\n// after (exact casing from 'dotnet ef dbcontext list')\ndotnet ef migrations add Init --context AppDbContext","handlingStrategy":"validation","validationCode":"// Before calling, enumerate context names and confirm the target exists.\nvar available = operations.CreateContextTypes().Select(t => t.Name).ToList();\nif (!available.Contains(contextName, StringComparer.OrdinalIgnoreCase))\n    throw new ArgumentException($\"Unknown context '{contextName}'. Known: {string.Join(\", \", available)}\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run 'dotnet ef dbcontext list' before scripting with --context.","Derive the --context value from a single source of truth (e.g. a config constant).","Keep one DbContext per assembly where practical to remove ambiguity."],"tags":["efcore","migrations","dbcontext","cli","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}