How to Save Your Own Types in Microsoft Agent Framework Workflow Checkpoints in C#
When a Microsoft Agent Framework workflow saves its checkpoints as JSON, each checkpoint holds the messages on their way between steps, including messages of types you wrote yourself. CheckpointManager.CreateJson takes JSON options for those types, and a JsonSerializerContext supplies them. Here's one small workflow run three ways: as a new console app runs it, with reflection-based JSON turned off, and with a context.
Microsoft's Checkpoints guide says what a checkpoint saves: A checkpoint captures the entire state of the workflow, and that includes All pending messages in the workflow for the next superstep. When a step sends a message of your own type, a checkpoint manager made with CreateJson has to write it as JSON, and read it back when a run resumes.
Syntax
CheckpointManager <checkpointManager> = CheckpointManager.CreateJson(<store>, <ContextName>.Default.Options);
[JsonSerializable(typeof(<YourType>))]
internal sealed partial class <ContextName> : JsonSerializerContext;
| Part | What it is |
|---|---|
CheckpointManager.CreateJson | Creates a new instance of the CheckpointManager that uses JSON serialization for checkpoint data. |
<checkpointManager> | Your variable. Pass it to InProcessExecution.RunAsync and ResumeAsync. |
<store> | Where the checkpoints are kept: The checkpoint store to use for persisting and retrieving checkpoint data as JSON elements. Cannot be null. |
<ContextName>.Default.Options | The customOptions argument, documented as Optional custom JSON serializer options to use for serialization and deserialization. Must be provided if using custom types in messages or state. Default is an instance of the context type with default options, and Options are its JSON options. |
[JsonSerializable(typeof(<YourType>))] | Asks the System.Text.Json source generator for the JSON code of <YourType>. Add one for each type of your own. |
<ContextName> | Your context class. Microsoft's first step: Create a partial class that derives from JsonSerializerContext. partial lets the generator write the rest of it when you build. |
The documentation says must. Step 7 shows a console app that gets by without a context anyway, and Step 9 shows where that stops.
The Example
A console app called TicketCheckpoints runs a workflow of two steps. OpenTicket turns a title into a Ticket, a record of the app's own with a title and a priority, and sends it to DescribeTicket, which turns it back into text. The run saves its checkpoints in files, and the first checkpoint holds the Ticket on its way to DescribeTicket. The app then resumes from that checkpoint, which reads the Ticket back from JSON. It runs three times: as a new console app is set up, with reflection-based JSON turned off, and with a JSON context. There's no AI model in it, so you don't need an Azure account.
Prerequisites
- The .NET 10 SDK.
dotnet --versionprints a version that starts with10.0.
Step 1: Create a Console App
In a terminal, in the folder where you keep your projects, create the app and move into it:
dotnet new console -o TicketCheckpoints
cd TicketCheckpoints
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring /Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj:
Restore succeeded.
dotnet new console creates a console app in a new TicketCheckpoints folder, and cd moves into it. Open the folder in VS Code, or TicketCheckpoints.csproj in Visual Studio.
Step 2: Add the Workflows Package
dotnet add package Microsoft.Agents.AI.Workflows --version 1.28.0
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/10.0.404/trustedroots/codesignctl.pem'.
info : X.509 certificate chain validation will use the fallback certificate bundle at '/usr/local/share/dotnet/sdk/10.0.404/trustedroots/timestampctl.pem'.
info : Adding PackageReference for package 'Microsoft.Agents.AI.Workflows' into project '/Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj'.
info : Restoring packages for /Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj...
info : CACHE https://api.nuget.org/v3/vulnerabilities/index.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2026.11.30.23.39.07/vulnerability.base.json
info : CACHE https://api.nuget.org/v3-vulnerabilities/2026.11.30.23.39.07/2026.12.03.05.39.24/vulnerability.update.json
info : Package 'Microsoft.Agents.AI.Workflows' is compatible with all the specified frameworks in project '/Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj'.
info : PackageReference for package 'Microsoft.Agents.AI.Workflows' version '1.28.0' added to file '/Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj'.
info : Generating MSBuild file /Users/you/source/TicketCheckpoints/obj/TicketCheckpoints.csproj.nuget.g.targets.
info : Writing assets file to disk. Path: /Users/you/source/TicketCheckpoints/obj/project.assets.json
log : Restored /Users/you/source/TicketCheckpoints/TicketCheckpoints.csproj (in 936 ms).
Microsoft.Agents.AI.Workflows has everything a workflow is made of, checkpoints included. --version keeps you on the version this guide used. The project file now references it:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>
</Project>
Step 3: Create a Checkpoint Manager That Writes JSON Files
Replace everything in Program.cs with:
using System.Text.Json;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;
Console.WriteLine($"Reflection-based serialization: {(JsonSerializer.IsReflectionEnabledByDefault ? "on" : "off")}");
using var store = new FileSystemJsonCheckpointStore(new DirectoryInfo("checkpoints"));
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store);
JsonSerializer.IsReflectionEnabledByDefaultsays whether System.Text.Json may use reflection, which works out how to write a type while the app runs: Gets a value that indicates whether unconfigured JsonSerializerOptions instances should default to the reflection-based DefaultJsonTypeInfoResolver. The app prints it first, because Step 8 turns it off.FileSystemJsonCheckpointStoreis the store, documented as a file system-based implementation of a JSON checkpoint store that persists checkpoint data and index information to disk using JSON files. It writes them to acheckpointsfolder in the project folder, where you run the app. Its documentation adds that callers should ensure Dispose is called to release file handles and system resources when the store is no longer needed, whichusingdoes when the app ends.CheckpointManager.CreateJson(store)creates the checkpoint manager, which writes each checkpoint as JSON into the store. It gets no JSON options yet: Step 10 adds them.
Step 4: Run the Workflow and Resume from Its First Checkpoint
Add this at the end of the file:
await using Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager);
PrintEvents(run.OutgoingEvents);
Console.WriteLine($"Status: {await run.GetStatusAsync()}, checkpoints saved: {run.Checkpoints.Count}");
if (run.Checkpoints.Count > 0)
{
// The first checkpoint holds the Ticket on its way to DescribeTicket. Resuming from it reads the Ticket back.
await using Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager);
Console.WriteLine("Resumed from the first checkpoint:");
PrintEvents(resumed.OutgoingEvents);
}
InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager)runs the workflow on the titlePrinter jams on page 2, and the checkpoint manager turns checkpoints on. Microsoft's Checkpoints guide: Checkpoints are created at the end of each superstep, after all executors in that superstep have completed their execution. A superstep is one round of the run, and in this workflow each step runs in a round of its own.run.GetStatusAsync()andrun.Checkpoints.Counttell how the run ended and how many checkpoints it saved.InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager)runs the workflow again from the first checkpoint: Resumes a non-streaming execution of the workflow from a checkpoint. It gets a newly built workflow, and the guide says what that one must keep: A rehydrated workflow must preserve the topology and executor identities of the workflow that created the checkpoint.BuildWorkflowbuilds the same steps with the same ids every time.- Resuming makes the checkpoint manager read the
Ticketback from the checkpoint's JSON, so the app checks both directions: writing aTicketand reading it.
Step 5: Print the Output or the Error
Add this at the end of the file:
static void PrintEvents(IEnumerable<WorkflowEvent> events)
{
foreach (WorkflowEvent workflowEvent in events)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($"Output: {output.Data}");
}
else if (workflowEvent is WorkflowErrorEvent error)
{
Console.WriteLine($"The run failed: {error.Exception?.GetType().Name}: {error.Exception?.Message}");
}
}
}
PrintEventsis a local function that the code above calls twice: for the run, and for the resumed run.WorkflowOutputEventcarries the workflow's output, and the method prints its data.WorkflowErrorEventis documented as Event triggered when a workflow encounters an error. ItsExceptionholds what went wrong, and the method prints the exception's type and message.
Step 6: Build the Workflow and Its Own Type
Add this at the end of the file:
static Workflow BuildWorkflow()
{
Func<string, Ticket> open = title => new Ticket(title, Priority: 2);
Func<Ticket, string> describe = ticket => $"{ticket.Title} (priority {ticket.Priority})";
ExecutorBinding openTicket = open.BindAsExecutor("OpenTicket");
ExecutorBinding describeTicket = describe.BindAsExecutor("DescribeTicket");
return new WorkflowBuilder(openTicket)
.AddEdge(openTicket, describeTicket)
.WithOutputFrom(describeTicket)
.Build();
}
// The app's own type: OpenTicket sends it to DescribeTicket.
public sealed record Ticket(string Title, int Priority);
openturns a title into aTicketwith priority 2, anddescribeturns aTicketinto text such asPrinter jams on page 2 (priority 2).BindAsExecutormakes each function a workflow step: Configures a function-based message handler as an executor with the specified identifier and options. The ids,OpenTicketandDescribeTicket, are how checkpoints name the steps.AddEdge(openTicket, describeTicket)sends theTicketfrom one step to the other, andWithOutputFrom(describeTicket)makes the text the workflow's output.public sealed record Ticket(string Title, int Priority);is the app's own type, a record with aTitleand aPriority. Between the two steps, aTicketis a message waiting forDescribeTicket, and that's what the first checkpoint has to save.
Step 7: Run It
dotnet run
Reflection-based serialization: on
Output: Printer jams on page 2 (priority 2)
Status: Idle, checkpoints saved: 2
Resumed from the first checkpoint:
Output: Printer jams on page 2 (priority 2)

Reflection is on, as it is in a new console app: the setting defaults to true if unset. The run printed its output and stopped Idle: it halted with no requests left to answer. It saved 2 checkpoints, one at the end of each superstep. Resuming from the first one printed the same output again, so the Ticket was written to JSON and read back, all without a JSON context.
The store wrote its JSON files to the checkpoints folder. In the first checkpoint, the one whose stepNumber is 0, this is the part that holds the Ticket:
"queuedMessages": {
"DescribeTicket": [
{
"messageType": {
"assemblyName": "TicketCheckpoints, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"typeName": "Ticket"
},
"message": {
"typeId": {
"assemblyName": "TicketCheckpoints, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null",
"typeName": "Ticket"
},
"value": {
"title": "Printer jams on page 2",
"priority": 2
}
},
"source": {
"id": "OpenTicket"
}
}
]
}
queuedMessages holds the messages waiting for the next superstep, here one for DescribeTicket from OpenTicket. It records the message's type, Ticket from the app's own assembly, TicketCheckpoints, and its value: the title and the priority. Writing that value, and reading it back, is the job of the checkpoint manager's JSON options.
Step 8: Turn Off Reflection-Based JSON
A console app has reflection-based JSON on, but not every app does. Microsoft's source generation guide: If you don't specify this property and PublishTrimmed is enabled, reflection-based serialization is automatically disabled. Native AOT apps can't rely on it either: calling a basic serialization method can break Native AOT apps, which doesn't support all required reflection APIs. The same guide suggests turning reflection off yourself, because then breaks are easier to diagnose. Do that here. In TicketCheckpoints.csproj, add this line to the PropertyGroup:
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
JsonSerializerIsReflectionEnabledByDefault set to false turns reflection-based JSON off for the whole app, as a trimmed app has it. The project file now reads:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>
</Project>
Step 9: Run It Again
dotnet run
Reflection-based serialization: off
The run failed: InvalidOperationException: No JSON type info is available for type 'Ticket'.
Status: Ended, checkpoints saved: 0

Nothing in Program.cs changed, and the run failed. With reflection off, the checkpoint manager's JSON options had no code for writing a Ticket, and the error names that type. There's no output, the run Ended, and it saved no checkpoints, so the app had nothing to resume from. Not even the first checkpoint was saved: that's the one that has to write the Ticket, at the end of the first superstep, and DescribeTicket never printed its output.
This is the case the documentation of CreateJson warns about: the JSON options Must be provided if using custom types in messages or state.
Step 10: Give the Checkpoint Manager a JSON Context
Three changes in Program.cs. Add a using line below using System.Text.Json;:
using System.Text.Json.Serialization;
Replace the CreateJson line with these two lines:
// TicketJsonContext gives the checkpoint manager the JSON code for this app's own types.
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store, TicketJsonContext.Default.Options);
And add the context at the end of the file:
// The source generator writes the JSON code for every type listed here when you build.
[JsonSerializable(typeof(Ticket))]
internal sealed partial class TicketJsonContext : JsonSerializerContext;
System.Text.Json.Serializationis the namespace ofJsonSerializableandJsonSerializerContext.[JsonSerializable(typeof(Ticket))]asks the source generator for the JSON code ofTicket. The generator runs while the project builds, so that code is part of the app before it starts, and it needs no reflection.internal sealed partial class TicketJsonContext : JsonSerializerContext;declares the context.partiallets the generator write its members.TicketJsonContext.Default.Optionsare the JSON options of the context, the run-time specified options of the context. Passed toCreateJson, they're what the checkpoint manager now uses to write and read aTicket.
Step 11: Run It with the Context
dotnet run
Reflection-based serialization: off
Output: Printer jams on page 2 (priority 2)
Status: Idle, checkpoints saved: 2
Resumed from the first checkpoint:
Output: Printer jams on page 2 (priority 2)

Reflection is still off, and everything works again: the output, 2 checkpoints, and the resume, which read the Ticket back. The JSON code for Ticket now comes from the context, built with the app, so the checkpoints no longer depend on reflection.
The Complete File
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.Agents.AI.Workflows;
using Microsoft.Agents.AI.Workflows.Checkpointing;
Console.WriteLine($"Reflection-based serialization: {(JsonSerializer.IsReflectionEnabledByDefault ? "on" : "off")}");
using var store = new FileSystemJsonCheckpointStore(new DirectoryInfo("checkpoints"));
// TicketJsonContext gives the checkpoint manager the JSON code for this app's own types.
CheckpointManager checkpointManager = CheckpointManager.CreateJson(store, TicketJsonContext.Default.Options);
await using Run run = await InProcessExecution.RunAsync(BuildWorkflow(), "Printer jams on page 2", checkpointManager);
PrintEvents(run.OutgoingEvents);
Console.WriteLine($"Status: {await run.GetStatusAsync()}, checkpoints saved: {run.Checkpoints.Count}");
if (run.Checkpoints.Count > 0)
{
// The first checkpoint holds the Ticket on its way to DescribeTicket. Resuming from it reads the Ticket back.
await using Run resumed = await InProcessExecution.ResumeAsync(BuildWorkflow(), run.Checkpoints[0], checkpointManager);
Console.WriteLine("Resumed from the first checkpoint:");
PrintEvents(resumed.OutgoingEvents);
}
static void PrintEvents(IEnumerable<WorkflowEvent> events)
{
foreach (WorkflowEvent workflowEvent in events)
{
if (workflowEvent is WorkflowOutputEvent output)
{
Console.WriteLine($"Output: {output.Data}");
}
else if (workflowEvent is WorkflowErrorEvent error)
{
Console.WriteLine($"The run failed: {error.Exception?.GetType().Name}: {error.Exception?.Message}");
}
}
}
static Workflow BuildWorkflow()
{
Func<string, Ticket> open = title => new Ticket(title, Priority: 2);
Func<Ticket, string> describe = ticket => $"{ticket.Title} (priority {ticket.Priority})";
ExecutorBinding openTicket = open.BindAsExecutor("OpenTicket");
ExecutorBinding describeTicket = describe.BindAsExecutor("DescribeTicket");
return new WorkflowBuilder(openTicket)
.AddEdge(openTicket, describeTicket)
.WithOutputFrom(describeTicket)
.Build();
}
// The app's own type: OpenTicket sends it to DescribeTicket.
public sealed record Ticket(string Title, int Priority);
// The source generator writes the JSON code for every type listed here when you build.
[JsonSerializable(typeof(Ticket))]
internal sealed partial class TicketJsonContext : JsonSerializerContext;

The project file keeps reflection-based JSON off, so a type you forget to list fails while you develop, and not only in a trimmed build:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<JsonSerializerIsReflectionEnabledByDefault>false</JsonSerializerIsReflectionEnabledByDefault>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Agents.AI.Workflows" Version="1.28.0" />
</ItemGroup>
</Project>
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Leaving the context out because the app works without it | It works only while reflection-based JSON is on. With it off, as in a trimmed app, the run fails with No JSON type info is available for type 'Ticket'. and saves no checkpoints | Pass a context's options to CreateJson from the start |
| Testing only with reflection on | A type you forgot to list fails only later, in a trimmed or Native AOT build | Set JsonSerializerIsReflectionEnabledByDefault to false while you develop |
| Listing only the types that travel in messages | A type of your own kept in the workflow's state goes into the checkpoint too | Add [JsonSerializable] for every type of your own in messages or in the state |
FAQ
Why did the first run work without a context?
Because reflection-based JSON was on. Microsoft's comparison of the two approaches: By default, JsonSerializer collects metadata at runtime by using reflection. With reflection, System.Text.Json works out how to write a Ticket the first time it meets one. With reflection off, only types whose JSON code was generated when the app was built can be written, and the context is what generates it.
Do the types of my type's properties need their own attribute?
No, with one exception. Microsoft's source generation guide says the types of a listed type's members don't need [JsonSerializable] attributes of their own, except members declared as object, whose types at run time have to be listed.
What else does a checkpoint hold?
The Checkpoints guide lists the current state of all executors, all pending messages for the next superstep, pending requests and responses, and shared states. A type of your own in any of them goes through the same JSON options.
Conclusion
A checkpoint saves the messages between a workflow's steps as JSON, and with them every type of your own. Give CheckpointManager.CreateJson the options of a JsonSerializerContext that lists those types with [JsonSerializable]. A console app with reflection-based JSON on gets by without one, but a trimmed app, or one that turns reflection off, fails as this run did, with No JSON type info is available for type 'Ticket'., and saves no checkpoints.
Additional Resources
- Checkpoints — when checkpoints are created, what they hold, and resuming from one.
- How to use source generation in System.Text.Json — contexts,
[JsonSerializable], and turning off reflection defaults. - Reflection versus source generation in System.Text.Json — what each approach does, and why Native AOT apps need source generation.
- JsonSerializer.IsReflectionEnabledByDefault — the setting the app prints.
Related
- How to Write a Custom Checkpoint Store for Microsoft Agent Framework Workflows in C#
- How to Resume a Microsoft Agent Framework Workflow from a Checkpoint After a Restart in C#
- Fixed: JsonTypeInfo metadata for type was not provided by TypeInfoResolver of type 'Microsoft.Extensions.AI.AIJsonUtilities+JsonContext'
- Fixed: "Reflection-based serialization has been disabled for this application" with dotnet run
