Skip to content

.NET: [Bug]: Exception in workflow, that is added as agent, results in json serialisation error message instead of exception #8012

Description

Description

Have a workflow that throws an exception. Have the workflow registered as an agent.

Call the agent. Instead of the actual exception being logged, it results in a JSON serialisation error towards the user.

This was an issue in Semantic Kernel already: microsoft/semantic-kernel#10708

Code Sample

var workflowAsAgent = builder
    .AddWorkflow("super-agent", CreateWorkflowDelegate)
    .AddAsAIAgent();  // Now the workflow can be used as an agent

Error Messages / Stack Traces

Internal (swallowed) exception:

Exception has occurred: CLR/System.InvalidOperationException
Exception thrown: 'System.InvalidOperationException' in Microsoft.Agents.AI.Workflows.dll: 'Executor 'AggregatorExecutor' cannot send messages of type 'MySolution.Workflow.RawAggregate'.'
   at Microsoft.Agents.AI.Workflows.InProc.InProcessRunnerContext.<SendMessageAsync>d__30.MoveNext() in /home/vsts/work/1/s/agent-framework/dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs:line 235

What the user sees:

Serialization and deserialization of 'System.Reflection.MethodBase' instances is not supported. Path: $.TargetSite. (Code: execution_error)

Image

Package Versions

    <PackageVersion Include="Microsoft.Agents.AI" Version="1.20.0" />
    <PackageVersion Include="Microsoft.Agents.AI.A2A" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.DevUI" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.A2A" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.A2A.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.AspNetCore" Version="1.20.0-preview.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Hosting.OpenAI" Version="1.20.0-alpha.260831.1" />
    <PackageVersion Include="Microsoft.Agents.AI.Workflows" Version="1.20.0" />
    <PackageVersion Include="Microsoft.Agents.AI.Workflows.Generators" Version="1.20.0" />

.NET Version

.Net 10.0

Additional Context

No response

Activity

  1. added
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Sep 2, 2026
  2. github-actions commented on Sep 2, 2026

    @github-actions
    Contributor

    🤖 Automated triage reproduction notes (agent-authored — trust but verify)

    Agent analysis

    The bug is in dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs::InvokeStageAsync at lines 538-552, where a WorkflowErrorEvent containing the original Exception is assigned to AgentResponseUpdate.RawRepresentation. It is triggered when a workflow-as-agent throws and a host serializes that raw representation. Minimal repro: run a throwing workflow through AsAIAgent(), select the emitted WorkflowErrorEvent raw representation, and serialize it with System.Text.Json.

    • Failing test: dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs
    • Files examined: dotnet/src/Microsoft.Agents.AI.Workflows/InProc/InProcessRunnerContext.cs, dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowSession.cs, dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowHostAgent.cs, dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowsJsonUtilities.cs, dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/InMemoryResponsesService.cs, dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowHostSmokeTests.cs
    • Tests run: WorkflowHostSmokeTests.Test_AsAgent_ErrorContentStreamedOutAsync, WorkflowHostSmokeTests.Test_AsAgent_WorkflowExceptionUpdateCanBeSerializedAsync
    • Reported version: 1.20.0
  3. added
    workflowsUsage: [Issues, PRs], Target: Workflows
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Sep 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .NetreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowworkflowsUsage: [Issues, PRs], Target: Workflows

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions