{"record":{"id":"eb576e7e163b38db","repo":"dotnet/efcore","slug":"the-current-csharpmigrationoperationgenerator-cann","errorCode":null,"errorMessage":"The current CSharpMigrationOperationGenerator cannot scaffold operations of type '{operationType}'. Configure your design-time services to use one that can.","messagePattern":"The current CSharpMigrationOperationGenerator cannot scaffold operations of type '(.+?)'\\. Configure your design-time services to use one that can\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs","lineNumber":69,"sourceCode":"            {\n                builder\n                    .AppendLine()\n                    .AppendLine();\n            }\n\n            builder.Append(builderName);\n            Generate((dynamic)operation, builder);\n            builder.Append(\";\");\n        }\n    }\n\n    /// <summary>\n    ///     Generates code for an unknown <see cref=\"MigrationOperation\" />.\n    /// </summary>\n    /// <param name=\"operation\">The operation.</param>\n    /// <param name=\"builder\">The builder code is added to.</param>\n    protected virtual void Generate(MigrationOperation operation, IndentedStringBuilder builder)\n        => throw new InvalidOperationException(DesignStrings.UnknownOperation(operation.GetType()));\n\n    /// <summary>\n    ///     Generates code for an <see cref=\"AddColumnOperation\" />.\n    /// </summary>\n    /// <param name=\"operation\">The operation.</param>\n    /// <param name=\"builder\">The builder code is added to.</param>\n    protected virtual void Generate(AddColumnOperation operation, IndentedStringBuilder builder)\n    {\n        builder\n            .Append(\".AddColumn<\")\n            .Append(Code.Reference(operation.ClrType))\n            .AppendLine(\">(\");\n\n        using (builder.Indent())\n        {\n            builder\n                .Append(\"name: \")\n                .Append(Code.Literal(operation.Name));","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Migrations/Design/CSharpMigrationOperationGenerator.cs#L51-L87","documentation":"CSharpMigrationOperationGenerator.Generate dispatches each MigrationOperation via a dynamic overload (line 58). If no specific Generate(TOperation) overload matches the runtime type, the call resolves to the base Generate(MigrationOperation, builder) which throws this InvalidOperationException. The fix is always to add a generator that knows your custom operation type.","triggerScenarios":"A custom MigrationOperation subclass (e.g. MyCreateTriggerOperation) is present in a migration's Up/Down list, but the registered CSharpMigrationOperationGenerator has no overload for it. The dynamic dispatch falls through to the fallback at line 68-69.","commonSituations":"Building a custom provider/extension that introduces a new MigrationOperation type but forgot to register a matching ICSharpMigrationOperationGenerator (or a derived CSharpMigrationOperationGenerator with the overload); upgrading EF Core removed an overload your provider relied on.","solutions":["Subclass CSharpMigrationOperationGenerator and add 'protected virtual void Generate(MyOperation op, IndentedStringBuilder b)'.","Register your generator in design-time services via IDesignTimeServices.ConfigureDesignTimeServices replacing ICSharpMigrationOperationGenerator.","If the operation is only SQL-relevant, also implement the corresponding SQL generator so the operation executes.","Re-add the migration after registering the generator so it re-scaffolds using the new overload."],"exampleFix":"// before: MyCreateTriggerOperation has no generator overload\npublic class MyCSharpMigrationOperationGenerator : CSharpMigrationOperationGenerator\n{\n    public MyCSharpMigrationOperationGenerator(CSharpMigrationOperationGeneratorDependencies d) : base(d) { }\n    protected virtual void Generate(MyCreateTriggerOperation op, IndentedStringBuilder b)\n        => b.AppendLine($\".CreateTrigger(name: {Code.Literal(op.Name)})\");\n}\n// register:\nservices.AddSingleton<ICSharpMigrationOperationGenerator, MyCSharpMigrationOperationGenerator>();","handlingStrategy":"validation","validationCode":"var known = new HashSet<Type>(supportedOperationTypes);\nforeach (var op in migration.Operations)\n    if (!known.Contains(op.GetType())) throw new InvalidOperationException($\"No generator for operation type {op.GetType()}.\");","typeGuard":"static bool CanGenerate(CSharpMigrationOperationGenerator g, MigrationOperation op)\n{ try { g.GetType().GetMethod(\"Generate\", new[] { op.GetType(), typeof(IndentedStringBuilder) }); return true; } catch { return false; } }","tryCatchPattern":null,"preventionTips":["Always pair a custom MigrationOperation with a generator overload.","Register the generator via IDesignTimeServices so it is picked up at scaffold time.","Add a unit test that scaffolds a migration containing each custom operation type."],"tags":["efcore","migrations","scaffolding","custom-provider","extensibility"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}