{"record":{"id":"1ed48596f5baee31","repo":"dotnet/efcore","slug":"could-not-load-assembly-assembly-ensure-it-is","errorCode":null,"errorMessage":"Could not load assembly '{assembly}'. Ensure it is referenced by the startup project '{startupProject}'.","messagePattern":"Could not load assembly '(.+?)'\\. Ensure it is referenced by the startup project '(.+?)'\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/OperationExecutor.cs","lineNumber":85,"sourceCode":"            && new SemanticVersionComparer().Compare(toolsVersion, runtimeVersion) < 0)\n        {\n            _reporter.WriteWarning(DesignStrings.VersionMismatch(toolsVersion, runtimeVersion));\n        }\n    }\n\n    private Assembly Assembly\n    {\n        get\n        {\n            Assembly Create()\n            {\n                try\n                {\n                    return Assembly.Load(new AssemblyName(_targetAssemblyName));\n                }\n                catch (Exception ex)\n                {\n                    throw new OperationException(\n                        DesignStrings.UnreferencedAssembly(_targetAssemblyName, _startupTargetAssemblyName),\n                        ex);\n                }\n            }\n\n            return field ??= Create();\n        }\n    }\n\n    private Assembly StartupAssembly\n        => field\n            ??= Assembly.Load(new AssemblyName(_startupTargetAssemblyName));\n\n    /// <summary>\n    ///     Exposes the underlying operations for testing.\n    /// </summary>\n    [EntityFrameworkInternal]\n    public virtual MigrationsOperations MigrationsOperations","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/OperationExecutor.cs#L67-L103","documentation":"OperationExecutor.Assembly is a lazy property that loads the target assembly by name. If Assembly.Load throws (FileNotFoundException, FileLoadException, BadImageFormatException, etc.), EF wraps it as a user-facing OperationException explaining that the assembly must be referenced by the startup project's output. The original exception is preserved as InnerException for diagnostics.","triggerScenarios":"OperationExecutor tries to Assembly.Load(new AssemblyName(_targetAssemblyName)) and the runtime cannot resolve it. This is the bootstrap step before any DbContext discovery, so it fires very early in any dotnet ef / PMC command.","commonSituations":"The target project references the assembly only at design time but it isn't an output dependency; the assembly name was mistyped or the project was renamed; multi-targeting produced a different output path; the startup project doesn't transitively reference the target; the assembly failed to build so its DLL is missing.","solutions":["Ensure the startup project has a project or assembly reference to the target assembly.","Build the startup project (dotnet build) so all referenced assemblies are present in the output.","Verify the assembly name spelling (it is the simple name, not a path).","If multi-targeting, ensure EF tools resolve the same TFM as the built output."],"exampleFix":"# before: startup project doesn't reference the data project\n# fix: add the reference\ndotnet add src/MyApp/MyApp.csproj reference src/MyApp.Data/MyApp.Data.csproj","handlingStrategy":"try-catch","validationCode":"try { var asm = Assembly.Load(new AssemblyName(targetAssemblyName)); }\ncatch (Exception ex) { /* report that the startup project must reference it */ throw; }","typeGuard":null,"tryCatchPattern":"try { var executor = new OperationExecutor(...); }\ncatch (OperationException ex) when (ex.Message.StartsWith(\"Could not load assembly\"))\n{ /* add project reference and rebuild */ }","preventionTips":["Make the startup project reference the target/data project.","Build before running EF tools.","Keep assembly names stable; avoid renames without updating references."],"tags":["assembly-loading","startup-project","design-time","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}