-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.Net: System.InvalidOperationException: Collection was modified; enumeration operation may not execute from Microsoft.SemanticKernel.Connectors.OpenAI #6058
Comments
Can you share a simple repro? |
I have the bug with this simple project |
Thanks! @SergeyMenshykh, you added this code: foreach (var argument in arguments)
{
arguments[argument.Key] = argument.Value?.ToString();
} That's generally invalid: you can't change the dictionary while you're enumerating it. |
That said, @gleborgne, I notice you're running on .NET Core 3.1. That is out of support. I also expect if you update to .NET 6, .NET 7, or .NET 8 this issue will go away for you, which is also likely why testing didn't flag it. It's ok on newer versions of .NET to mutate the dictionary in this way as long as it doesn't increase its size, which it shouldn't in the cited case because the key should always be there. (But, @SergeyMenshykh, as long as we need to support .NET Framework, this is still an issue there.) |
Well, I will be glad upgrading but on a legacy project with a few hundred thousands lines of code it's not that simple |
Unrelated to the point of this issue, but I'm curious, what issues are you hitting when you upgrade from .NET Core 3.1 to .NET 6 that make it not simple? |
We have custom code on top of entity framework for handling dynamic queries on json data in Azure SQL. And upgrading to .net 8 means rewriting a lot of that code because EF has a lot of breaking changes. |
### Motivation and Context Resolve #6058 --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
@gleborgne Shay here from the EF team - am interested in hearing about the breaking changes which you refer to above, could you provide a bit more detail on your experience? |
We are using a lot of low level APIs and a few hacks to inject what we need in the generated SQL queries. Those low level APIs have changed since EF Core 2.x. As far as I remember, those parts of EF where re-written by the EF Team for handling CosmosDb, and handling json natively in EF Core. |
Just to be sure, are you saying you used APIs flagged as "internal"? If not, can you give an example of API(s) you were using which broke? |
Hi! |
Reading above - I need to voice that I do hope too you keep supporting older .NET versions as some of us are stuck there "forever" due to WebForms (EF6 to Core seems manageable but scary). I just converted all API to this - but found this issue too late. All else is working fine (Dalle-3 and function calls via streaming chat, whisper, embedding, llama3) spite the state / all the pragma warning disable needed. Sometimes it was a bit of a headache with e.g. some ctors being internal. NOTE: You can use the streaming option as a work around until this is fixed. |
@markwallace-microsoft, can you comment?
Yes. That hasn't changed. This just slipped through testing, as CI currently only runs tests on .NET Core. #6063 tracks adding a .NET Framework leg to CI. |
…6067) ### Motivation and Context Resolve microsoft#6058 --------- Co-authored-by: Stephen Toub <stoub@microsoft.com>
Describe the bug
I try upgrading from 1.7.1 but any version above that I tried are throwing exceptions when I am using GetChatMessageContentsAsync. If using GetStreamingChatMessageContentsAsync with the exact same parameters everything is working fine.
I am using Azure Open AI with a few kernel plugins and ToolCallBehavior = ToolCallBehavior.AutoInvokeKernelFunctions,.
System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext()
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetChatMessage(ChatChoice chatChoice, ChatCompletions responseData)
at Microsoft.SemanticKernel.Connectors.OpenAI.ClientCore.GetChatMessageContentsAsync(ChatHistory chat, PromptExecutionSettings executionSettings, Kernel kernel, CancellationToken cancellationToken)
From what I can see from the logs, the call to Azure Open AI was done and the problem is when linking to the kernel functions.
To Reproduce
Steps to reproduce the behavior:
Expected behavior
no error ?
Platform
The text was updated successfully, but these errors were encountered: