diff --git a/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs b/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs index 0a6b9218f7..8141be1075 100644 --- a/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs +++ b/dotnet/src/Microsoft.Agents.AI.Workflows/SwitchBuilder.cs @@ -36,10 +36,12 @@ public sealed class SwitchBuilder Throw.IfNull(executors); HashSet indicies = []; + int executorIndex = 0; foreach (ExecutorBinding executor in executors) { - Throw.IfNull(executor); + Throw.IfNull(executor, $"{nameof(executors)}[{executorIndex}]"); + executorIndex++; if (!this._executorIndicies.TryGetValue(executor.Id, out int index)) { @@ -66,9 +68,12 @@ public sealed class SwitchBuilder { Throw.IfNull(executors); + int executorIndex = 0; + foreach (ExecutorBinding executor in executors) { - Throw.IfNull(executor); + Throw.IfNull(executor, $"{nameof(executors)}[{executorIndex}]"); + executorIndex++; if (!this._executorIndicies.TryGetValue(executor.Id, out int index)) { diff --git a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowBuilderSmokeTests.cs b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowBuilderSmokeTests.cs index 4997197445..c2b855b8bf 100644 --- a/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowBuilderSmokeTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/WorkflowBuilderSmokeTests.cs @@ -445,9 +445,9 @@ public partial class WorkflowBuilderSmokeTests // Act/Assert Assert.Throws("predicate", () => switchBuilder.AddCase(null!, [target])); Assert.Throws("executors", () => switchBuilder.AddCase(_ => true, null!)); - Assert.Throws("executor", () => switchBuilder.AddCase(_ => true, [target, null!])); + Assert.Throws("executors[1]", () => switchBuilder.AddCase(_ => true, [target, null!])); Assert.Throws("executors", () => switchBuilder.WithDefault(null!)); - Assert.Throws("executor", () => switchBuilder.WithDefault([target, null!])); + Assert.Throws("executors[1]", () => switchBuilder.WithDefault([target, null!])); } ///