Fixed: MAFGENWF003 Class 'CountWordsExecutor' contains [MessageHandler] methods but is not declared as partial
With the workflows source generator installed, one of my Microsoft Agent Framework executor classes failed to build with error MAFGENWF003: Class 'CountWordsExecutor' contains [MessageHandler] methods but is not declared as partial, and a CS0534 for the same class came with it. The class was missing one keyword: partial.
What I Was Doing
I was building WordCount, a small console app with a two-step workflow: CleanText removes the extra spaces from a text, and CountWords counts its words. Both steps are class-based executors, classes that derive from Executor with one method marked [MessageHandler]. The project referenced Agent Framework's workflows package, Microsoft.Agents.AI.Workflows 1.28.0, and its source generator, Microsoft.Agents.AI.Workflows.Generators 1.28.0.
CleanTextExecutor was declared partial. CountWordsExecutor, on line 35 of Program.cs, was declared like an ordinary class:
// Step 2: takes a clean text and returns how many words it has.
internal sealed class CountWordsExecutor() : Executor("CountWords")
{
[MessageHandler]
private int Handle(string text, IWorkflowContext context) => text.Split(' ').Length;
}
What I Expected
The app to build and print each executor's result, then the workflow's output: 4, the number of words. Nothing in the class's own code uses another part of a class, so I didn't expect it to need partial.
What I Got
dotnet run
/Users/you/source/WordCount/Program.cs(35,23): error MAFGENWF003: Class 'CountWordsExecutor' contains [MessageHandler] methods but is not declared as partial
/Users/you/source/WordCount/Program.cs(35,23): error CS0534: 'CountWordsExecutor' does not implement inherited abstract member 'Executor.ConfigureProtocol(ProtocolBuilder)'
The build failed. Fix the build errors and run again.

What I Checked
Where the errors point. Both errors are at line 35, column 23: the name CountWordsExecutor in internal sealed class CountWordsExecutor(). CleanTextExecutor, declared partial in the same file, got no error.
Where MAFGENWF003 comes from. The ID and its message are in the workflows source generator, the analyzer that Microsoft.Agents.AI.Workflows.Generators adds to the build. A source generator is a tool that runs while the project compiles and adds code to it. This one found a [MessageHandler] method in a class it couldn't add code to, and said so.
What Microsoft's documentation requires. The Executors guide: The class must be marked partial to enable source generation. The remarks of MessageHandlerAttribute in the 1.28.0 package documentation say the same: The containing class must be partial and derive from Executor. My class derived from Executor but wasn't partial.
Why CS0534 came too. Executor has an abstract method, ConfigureProtocol(ProtocolBuilder), and the generator is what writes it, from the [MessageHandler] methods. It writes it as another part of the class, and C# joins the parts of a class only by this rule from Microsoft's C# guide: All the parts must use the partial keyword. So the generator left CountWordsExecutor alone, the method was never written, and the compiler reported the same CS0534 it gives when the generator package is missing (Fixed: CS0534 'CountWordsExecutor' does not implement inherited abstract member 'Executor.ConfigureProtocol(ProtocolBuilder)').
The Fix
Declare the class partial:
// Step 2: takes a clean text and returns how many words it has.
internal sealed partial class CountWordsExecutor() : Executor("CountWords")
{
[MessageHandler]
private int Handle(string text, IWorkflowContext context) => text.Split(' ').Length;
}
The keyword goes right before class, after internal and sealed. C# is strict about that: The partial modifier can only appear immediately before the keyword class, struct, or interface.
After the Fix
dotnet run
CleanText returned: the quick brown fox
CountWords returned: 4
The workflow's output: 4

Both errors are gone. With partial, the generator added its part to CountWordsExecutor, as it already did for CleanTextExecutor, and the workflow counted four words.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
Declaring an executor class with [MessageHandler] methods but no partial | MAFGENWF003, plus CS0534 for that class | Declare it partial |
Putting partial before the other modifiers, as in partial internal sealed class | C# doesn't allow it: partial can only appear immediately before class | Write internal sealed partial class |
Adding partial without the generator package | CS0534 on every executor class (Fixed) | Reference Microsoft.Agents.AI.Workflows.Generators too |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| MAFGENWF003 and CS0534 at the same line and column | That class has [MessageHandler] methods and isn't partial | Add partial before class |
| CS0534 on every executor class, with no MAFGENWF003 | The generator package isn't in the project | Add Microsoft.Agents.AI.Workflows.Generators |
FAQ
Can an executor class stay internal and sealed?
Yes. partial only adds to the declaration. Microsoft's own examples declare executors as internal sealed partial class, the same as CleanTextExecutor and CountWordsExecutor here.
Do other attributes need partial too?
Yes. Microsoft's Executors guide says that with the generator referenced, a class with the class-level [SendsMessage] or [YieldsOutput] attributes must be partial as well, so the generator can add its protocol configuration.
Conclusion
MAFGENWF003: Class 'CountWordsExecutor' contains [MessageHandler] methods but is not declared as partial means the workflows source generator found handler methods in a class it can't add code to. The CS0534 next to it follows from that: the method the generator would have written is missing. Add partial right before class, and both errors go away.
Additional Resources
- Executors — class-based executors and why the class must be
partial. - Partial Classes and Members — how C# joins the parts of a class, and where
partialgoes.
