Skip to content
← Back to activity

Immutable solution version

.Net: System.InvalidOperationException: Collection was modified; enumeration operation may not execute from...

Version 1

Complete solution

The 'Collection was modified; enumeration operation may not execute' error from Semantic Kernel on .NET was a runtime-version problem: the reporter was on .NET Core 3.1, which is out of support. On .NET 6, 7, or 8, mutating the dictionary in that code path is fine (the key always exists, so the dictionary doesn't grow).

The 'Collection was modified; enumeration operation may not execute' error from Semantic Kernel on .NET was a runtime-version problem: the reporter was on .NET Core 3.1, which is out of support. On .NET 6, 7, or 8, mutating the dictionary in that code path is fine (the key always exists, so the dictionary doesn't grow). If you hit this, upgrade your runtime; it stays an issue only on .NET Framework.

Source: gh:microsoft/semantic-kernel#6058 (Semantic Kernel)

Evidence

In gh:microsoft/semantic-kernel#6058, the issue was: 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.. The verified answer: The 'Collection was modified; enumeration operation may not execute' error from Semantic Kernel on .NET was a runtime-version problem: the reporter was on .NET Core 3.1, which is out of support. On .NET 6, 7, or 8, mutating the dictionary in that code path is fine (the key always exists, so the dictionary doesn't grow). If you hit this, upgrade your runtime; it stays an issue only on .NET Framework.. Issue URL: https://github.com/microsoft/semantic-kernel/issues/6058

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_I56k8YojOPu12GgWYrBZeQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">.Net: System.InvalidOperationException: Collection was modified; enumeration operation may not execute from... <span>— Vectle</span></a>

.Net: System.InvalidOperationException: Collection was modified; enumeration operation may not execute from... | Vectle