{"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":488,"sourceCode":"        }\n    }\n\n    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":470,"sourceCodeEnd":494,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/MigrationsOperations.cs#L470-L494","documentation":"EnsureMigrationsAssembly detected that the assembly EF is running commands from (_assembly, i.e. the project containing the migrations files on disk) does not match the configured MigrationsAssembly on the DbContext options. This guard prevents writing migration files into one project while the runtime expects them from another, which would silently break migration discovery.","triggerScenarios":"options.UseSqlServer(..., b => b.MigrationsAssembly(\"DataProject\")) but you ran 'dotnet ef' from WebProject whose assembly name is 'WebProject'. At line 479-489, _assembly != MigrationsAssemblyObject and assemblyName.Name != migrationsAssemblyName.","commonSituations":"Multi-project solution where migrations live in a dedicated Data assembly but the entry project is different; dev ran dotnet ef from the wrong directory; migrations assembly configured without the matching --project.","solutions":["Run dotnet ef from / point --project at the migrations assembly: dotnet ef migrations add X -p Data -s Web.","Or change the MigrationsAssembly in OnConfiguring to match the project you run from.","Keep the configuration and the CLI project consistent: the value of MigrationsAssembly must equal the assembly named by --project."],"exampleFix":"// before: ran from Web project, migrations configured for Data\n// Web/OnConfiguring:\noptions.UseSqlServer(cs, b => b.MigrationsAssembly(\"Data\"));\n// after: run from the right project\ndotnet ef migrations add Init -p ../Data -s .","handlingStrategy":"validation","validationCode":"var configured = RelationalOptionsExtension.Extract(contextOptions).MigrationsAssembly;\nif (!string.Equals(configured, targetAssembly.GetName().Name, StringComparison.Ordinal)) throw new InvalidOperationException(\"MigrationsAssembly mismatch; align --project with the configured value.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Make the --project you run dotnet ef from equal to the configured MigrationsAssembly.","Centralize the migrations-assembly name in a shared constant.","Document the canonical CLI invocation in each repo's README."],"tags":["efcore","migrations","multi-project","configuration","cli"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}