Description
Getting an exception on my await for each loop using the AIAgent .RunStreamingAsync() method. Occurs after the web search tool completes. But it does seem like maybe this operation isnt thread safe? Difficult to know exactly because I'm struggling to reproduce, I might have something wrong in my main application as well.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
at System.Collections.Generic.List1.Enumerator.MoveNext() at Microsoft.Extensions.AI.ChatResponseExtensions.CoalesceWebSearchToolCallContent(IList1 contents)
at Microsoft.Extensions.AI.ChatResponseExtensions.CoalesceContent(IList1 contents) at Microsoft.Extensions.AI.ChatResponseExtensions.FinalizeResponse(ChatResponse response) at Microsoft.Extensions.AI.ChatResponseExtensions.ToChatResponse(IEnumerable1 updates)
at Microsoft.Agents.AI.ChatClientAgent.d__29.MoveNext()
at Microsoft.Agents.AI.ChatClientAgent.d__29.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at Microsoft.Agents.AI.AIAgent.d__33.MoveNext()
at Microsoft.Agents.AI.AIAgent.d__33.MoveNext()
at Microsoft.Agents.AI.AIAgent.d__33.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at IMEG_Euclid.Agent.AI.Sessions.AgentSession.d__5.MoveNext() in D:\repos\IMEG_Euclid\IMEG_Euclid.Agent\AI\Sessions\AgentSession.cs:line 52
This exception was originally thrown at this call stack:
[External Code]
IMEG_Euclid.Agent.AI.Sessions.AgentSession.RunStreamingAsync(System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.ChatMessage>, IMEG_Euclid.Agent.AI.AIInvocationOptions, System.Threading.CancellationToken) in AgentSession.cs
Reproduction Steps
Unable to reproduce on smaller scale application.
Expected behavior
No exception.
Actual behavior
Exception.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Description
Getting an exception on my await for each loop using the AIAgent .RunStreamingAsync() method. Occurs after the web search tool completes. But it does seem like maybe this operation isnt thread safe? Difficult to know exactly because I'm struggling to reproduce, I might have something wrong in my main application as well.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=System.Private.CoreLib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException_InvalidOperation_EnumFailedVersion()
at System.Collections.Generic.List
1.Enumerator.MoveNext() at Microsoft.Extensions.AI.ChatResponseExtensions.CoalesceWebSearchToolCallContent(IList1 contents)at Microsoft.Extensions.AI.ChatResponseExtensions.CoalesceContent(IList
1 contents) at Microsoft.Extensions.AI.ChatResponseExtensions.FinalizeResponse(ChatResponse response) at Microsoft.Extensions.AI.ChatResponseExtensions.ToChatResponse(IEnumerable1 updates)at Microsoft.Agents.AI.ChatClientAgent.d__29.MoveNext()
at Microsoft.Agents.AI.ChatClientAgent.d__29.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at Microsoft.Agents.AI.AIAgent.d__33.MoveNext()
at Microsoft.Agents.AI.AIAgent.d__33.MoveNext()
at Microsoft.Agents.AI.AIAgent.d__33.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult(Int16 token)
at IMEG_Euclid.Agent.AI.Sessions.AgentSession.d__5.MoveNext() in D:\repos\IMEG_Euclid\IMEG_Euclid.Agent\AI\Sessions\AgentSession.cs:line 52
This exception was originally thrown at this call stack:
[External Code]
IMEG_Euclid.Agent.AI.Sessions.AgentSession.RunStreamingAsync(System.Collections.Generic.IReadOnlyList<Microsoft.Extensions.AI.ChatMessage>, IMEG_Euclid.Agent.AI.AIInvocationOptions, System.Threading.CancellationToken) in AgentSession.cs
Reproduction Steps
Unable to reproduce on smaller scale application.
Expected behavior
No exception.
Actual behavior
Exception.
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response