From 9a02dafbc36a06786cdb007d401c530eee13d00a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 13 May 2026 19:14:55 +0000 Subject: [PATCH] Clarify null element validation messages Agent-Logs-Url: https://github.com/microsoft/agent-framework/sessions/af831ee2-0a99-4427-9ffd-a3b5022c1b3b Co-authored-by: lokitoth <6936551+lokitoth@users.noreply.github.com> --- .../SwitchBuilder.cs | 18 ++++++++++++++---- .../WorkflowBuilderExtensions.cs | 4 +++- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs index 286329b6ec..c347ca84f3 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs @@ -37,9 +37,13 @@ public sealed class SwitchBuilder HashSet indicies = []; - foreach (ExecutorBinding executor in executors) + int executorIndex = 0; + foreach (ExecutorBinding? executor in executors) { - Throw.IfNull(executor, nameof(executors)); + if (executor is null) + { + throw new ArgumentNullException(nameof(executors), $"Executors collection contains a null element at index {executorIndex}."); + } if (!this._executorIndicies.TryGetValue(executor.Id, out int index)) { @@ -49,6 +53,7 @@ public sealed class SwitchBuilder } indicies.Add(index); + executorIndex++; } Func casePredicate = WorkflowBuilder.CreateConditionFunc(predicate)!; @@ -66,9 +71,13 @@ public sealed class SwitchBuilder { Throw.IfNull(executors); - foreach (ExecutorBinding executor in executors) + int executorIndex = 0; + foreach (ExecutorBinding? executor in executors) { - Throw.IfNull(executor, nameof(executors)); + if (executor is null) + { + throw new ArgumentNullException(nameof(executors), $"Executors collection contains a null element at index {executorIndex}."); + } if (!this._executorIndicies.TryGetValue(executor.Id, out int index)) { @@ -78,6 +87,7 @@ public sealed class SwitchBuilder } this._defaultIndicies.Add(index); + executorIndex++; } return this; diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs index 179dc78c88..c261036c6b 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/WorkflowBuilderExtensions.cs @@ -128,14 +128,16 @@ public static class WorkflowBuilderExtensions Throw.IfNull(targets); List targetList = []; + int targetIndex = 0; foreach (ExecutorBinding? target in targets) { if (target is null) { - throw new ArgumentNullException(nameof(targets), "Targets collection cannot contain null elements."); + throw new ArgumentNullException(nameof(targets), $"Targets collection contains a null element at index {targetIndex}."); } targetList.Add(target); + targetIndex++; } Throw.IfNullOrEmpty(targetList, nameof(targets));