From ca36b140c6f466c02a91b4571fd7c5d242212a40 Mon Sep 17 00:00:00 2001 From: Haiping Date: Sat, 24 May 2025 16:30:14 -0500 Subject: [PATCH] Fix CheckArgType null --- .../Services/ConversationStateService.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs index c41d3110..7cc5ea1e 100644 --- a/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs +++ b/src/Infrastructure/BotSharp.Core/Conversations/Services/ConversationStateService.cs @@ -415,7 +415,18 @@ public class ConversationStateService : IConversationStateService private bool CheckArgType(string name, string value) { - var agentTypes = AgentService.AgentParameterTypes.SelectMany(p => p.Value).ToList(); + // Defensive: Ensure AgentParameterTypes is not null or empty and values are not null + if (AgentService.AgentParameterTypes == null || !AgentService.AgentParameterTypes.Any()) + return true; + + var agentTypes = AgentService.AgentParameterTypes + .Where(p => p.Value != null) + .SelectMany(p => p.Value) + .ToList(); + + if (agentTypes == null || agentTypes.Count == 0) + return true; + var found = agentTypes.FirstOrDefault(t => t.Key == name); if (found.Key != null) {