{"record":{"id":"67972f1a4188dc6d","repo":"dotnet/efcore","slug":"no-dbcontext-was-found-in-assembly-assembly-e-67972f","errorCode":null,"errorMessage":"No DbContext was found in assembly '{assembly}'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.","messagePattern":"No DbContext was found in assembly '(.+?)'\\. Ensure that you're using the correct assembly and that the type is neither abstract nor generic\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":171,"sourceCode":"        bool noConnect)\n    {\n        if (contextType == \"*\")\n        {\n            var anyContext = false;\n            var contextsList = new List<MigrationInfo>();\n\n            foreach (var contextItem in _contextOperations.CreateAllContexts())\n            {\n                anyContext = true;\n                using (contextItem)\n                {\n                    contextsList.AddRange(GetMigrationsContext(contextItem, connectionString, noConnect));\n                }\n            }\n\n            if (!anyContext)\n            {\n                throw new OperationException(DesignStrings.NoContext(_assembly.GetName().Name));\n            }\n        }\n\n        using var context = _contextOperations.CreateContext(contextType);\n        {\n            return GetMigrationsContext(context, connectionString, noConnect);\n        }\n    }\n\n    private IEnumerable<MigrationInfo> GetMigrationsContext(DbContext context, string? connectionString, bool noConnect)\n    {\n        if (connectionString is not null)\n        {\n            context.Database.SetConnectionString(connectionString);\n        }\n\n        var services = _servicesBuilder.Build(context);\n        EnsureServices(services);","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L153-L189","documentation":"GetMigrations with contextType=='*' iterated CreateAllContexts and found zero DbContext types in the target assembly, so anyContext stayed false. EF cannot list migrations because no context exists to host them. The message reminds that abstract or generic contexts are excluded from discovery.","triggerScenarios":"'dotnet ef migrations list --context *' (or GetMigrations with wildcard) and CreateAllContexts yields nothing. The same guard exists so a wildcard run fails fast instead of silently producing empty output.","commonSituations":"Wrong assembly scanned (no --project pointing at the assembly containing the context); all contexts are abstract or generic-open; context is in a referenced class library not in the entry project; project not rebuilt after adding the context.","solutions":["Confirm a public, concrete, non-generic DbContext subclass exists in the scanned assembly.","Pass --project <assembly-with-context> so EF scans the right binary.","Rebuild the project so the freshly compiled context type is loaded.","Drop the '*' and pass an explicit context name once you know one exists."],"exampleFix":"// before\ndotnet ef migrations list --context *   // from Web project, context in Data project\n// after\ndotnet ef migrations list --context * -p ../Data -s .","handlingStrategy":"validation","validationCode":"var contexts = AppDomain.CurrentDomain.GetAssemblies()\n    .SelectMany(a => a.GetTypes())\n    .Where(t => typeof(DbContext).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericType)\n    .ToList();\nif (contexts.Count == 0) throw new InvalidOperationException(\"No discoverable DbContext in scanned assembly.\");","typeGuard":"static bool HasConcreteContext(Assembly asm) => asm.GetTypes()\n    .Any(t => typeof(DbContext).IsAssignableFrom(t) && !t.IsAbstract && !t.IsGenericType);","tryCatchPattern":null,"preventionTips":["Point --project at the assembly that defines the context.","Keep contexts concrete and closed (no open generics).","Rebuild before running design-time commands."],"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"}