{"record":{"id":"24796e5fc4f5e629","repo":"dotnet/efcore","slug":"your-target-project-assembly-doesn-t-match-you","errorCode":null,"errorMessage":"Your target project '{assembly}' doesn't match your migrations assembly '{migrationsAssembly}'. Either change your target project or change your migrations assembly.\nChange your migrations assembly by using DbContextOptionsBuilder. E.g. options.UseSqlServer(connection, b => b.MigrationsAssembly(\"{assembly}\")). By default, the migrations assembly is the assembly containing the DbContext.\nChange your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing \"dotnet ef\" from the directory containing the migrations project.","messagePattern":"Your target project '\\{assembly\\}' doesn't match your migrations assembly '\\{migrationsAssembly\\}'\\. Either change your target project or change your migrations assembly\\.\nChange your migrations assembly by using DbContextOptionsBuilder\\. E\\.g\\. options\\.UseSqlServer\\(connection, b => b\\.MigrationsAssembly\\(\"\\{assembly\\}\"\\)\\)\\. By default, the migrations assembly is the assembly containing the DbContext\\.\nChange your target project to the migrations project by using the Package Manager Console's Default project drop-down list, or by executing \"dotnet ef\" from the directory containing the migrations project\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/MigrationsOperations.cs","lineNumber":491,"sourceCode":"    private void EnsureMigrationsAssembly(IServiceProvider services)\n    {\n        var assemblyName = _assembly.GetName();\n        var options = services.GetRequiredService<IDbContextOptions>();\n        var contextType = services.GetRequiredService<ICurrentDbContext>().Context.GetType();\n        var optionsExtension = RelationalOptionsExtension.Extract(options);\n        if (optionsExtension.MigrationsAssemblyObject == null\n            || optionsExtension.MigrationsAssemblyObject != _assembly)\n        {\n            var migrationsAssemblyName = optionsExtension.MigrationsAssembly\n                ?? optionsExtension.MigrationsAssemblyObject?.GetName().Name\n                ?? contextType.Assembly.GetName().Name;\n            if (assemblyName.Name != migrationsAssemblyName\n                && assemblyName.FullName != migrationsAssemblyName)\n            {\n                throw new OperationException(\n                    DesignStrings.MigrationsAssemblyMismatch(assemblyName.Name, migrationsAssemblyName));\n            }\n        }\n    }\n}\n","sourceCodeStart":473,"sourceCodeEnd":494,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L473-L494","documentation":"EnsureMigrationsAssembly checks that the assembly EF loaded the context from (_assembly, i.e. the target project) matches the configured MigrationsAssembly. If they differ (by simple name or full name), EF refuses to write migrations into an assembly other than the one you're running from, because the files would land in the wrong project and the snapshot would diverge. The error text is long and prescriptive because this is a very common configuration mistake.","triggerScenarios":"EnsureMigrationsAssembly runs on every migration-scaffolding operation. It throws when RelationalOptionsExtension.MigrationsAssemblyObject is either null or not equal to _assembly AND the resolved migrations assembly name does not match _assembly.GetName().Name (or FullName). Concretely: you ran 'dotnet ef migrations add' from project A but the context's UseSqlServer(... b => b.MigrationsAssembly(\"B\")) points at project B.","commonSituations":"Solution layout: startup project != migrations project, and UseSqlServer's MigrationsAssembly points at the class library but you ran tooling from the startup app (or vice versa); copy-pasted options configuration carrying a hardcoded assembly name; renamed the data project without updating the MigrationsAssembly call.","solutions":["Run EF tooling from the project that the MigrationsAssembly is configured to: 'dotnet ef ... --project <DataLibrary> --startup-project <StartupApp>'.","Or change the MigrationsAssembly in OnConfiguring/UseSqlServer to match the project you run tooling from: options.UseSqlServer(conn, b => b.MigrationsAssembly(typeof(MyContext).Assembly.GetName().Name)).","Use the PMC 'Default project' drop-down to select the migrations project.","After renaming a project, update any literal MigrationsAssembly string."],"exampleFix":"// before: tooling run from MyApp, but context says migrations live in MyApp.Data\noptions.UseSqlServer(conn, b => b.MigrationsAssembly(\"MyApp.Data\"));\n// fix option A: run from the data project\ndotnet ef migrations add Init --project MyApp.Data --startup-project MyApp\n// fix option B: align the assembly with the running project\noptions.UseSqlServer(conn, b => b.MigrationsAssembly(\"MyApp\"));","handlingStrategy":"validation","validationCode":"var ext = RelationalOptionsExtension.Extract(dbContextOptions);\nvar configured = ext?.MigrationsAssembly ?? context.GetType().Assembly.GetName().Name;\nif (!string.Equals(configured, targetAssembly.GetName().Name, StringComparison.Ordinal)\n    && !string.Equals(configured, targetAssembly.GetName().FullName, StringComparison.Ordinal))\n{\n    throw new InvalidOperationException($\"Migrations assembly '{configured}' != target '{targetAssembly.GetName().Name}'.\");\n}","typeGuard":null,"tryCatchPattern":"try { operations.AddMigration(...); }\ncatch (OperationException ex) when (ex.Message.Contains(\"doesn't match your migrations assembly\"))\n{ /* align --project with MigrationsAssembly or vice versa */ }","preventionTips":["Derive MigrationsAssembly from typeof(Context).Assembly rather than hardcoding a name.","Run EF tooling with explicit --project/--startup-project matching the layout.","Update MigrationsAssembly literals after project renames."],"tags":["migrations","assembly","project-layout","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}