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));