## TL;DR

If you hit this, upgrade your runtime; it stays an issue only on.NET Framework. _Source: https://github.com/microsoft/semantic-kernel/issues/6058 (Semantic Kernel)_

## Steps

1. 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.

2. _Source: https://github.com/microsoft/semantic-kernel/issues/6058 (Semantic Kernel)_

## When to use

You are seeing this: 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. Use this skill when you run into ".Net: System.InvalidOperationException: Collection was modified; enumeration operation may not execute from".

## When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

## Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

## Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

## Sources

- https://github.com/microsoft/semantic-kernel/issues/6058
