stride3d/stride · error · NotSupportedException
NotSupportedException
Error message
NotSupportedException
What it means
SortedDictionary<TKey,TValue>.KeyCollection is a read-only view over the dictionary's keys; its explicit ICollection<TKey>.Add always throws NotSupportedException. You cannot add a key through the KeyCollection — keys are only created by adding entries to the dictionary itself.
Solutions
- Add to the dictionary itself: dict[key] = value; which creates the key.
- If a mutable key list is needed, copy first: var keys = new List<TKey>(dict.Keys); then keys.Add(...).
- Change generic helpers to accept IEnumerable<TKey> when mutation isn't intended, or document that callers must pass mutable collections.
Example fix
// before
ICollection<string> keys = dict.Keys;
keys.Add("newKey"); // NotSupportedException
// after
dict["newKey"] = value; // add via the dictionary
// or
var keys = new List<string>(dict.Keys);
keys.Add("newKey"); Defensive patterns
Strategy: type-guard
Type guard
static bool CanAdd<T>(ICollection<T> c) => !c.IsReadOnly;
Try / catch
try { keysCollection.Add(key); }
catch (NotSupportedException) { dict[key] = value; // add through the dictionary instead } Prevention
- Treat dict.Keys as IReadOnlyCollection<TKey> — never store it in an ICollection<TKey> variable
- Add new keys via the dictionary indexer or Add method, not the Keys view
- In generic code, check IsReadOnly before calling Add
When it happens
Trigger: Casting the Keys collection to ICollection<TKey> (or assigning it to an ICollection<TKey> variable) and calling Add(key), e.g. through generic code that adds to any ICollection<TKey> it receives.
Common situations: Generic helper methods that accept ICollection<TKey> and call Add, handed dict.Keys; LINQ-adjacent code paths that assume any ICollection is mutable; refactoring from List<TKey> (mutable) to dict.Keys (read-only view).
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Two bundles with name
- content reference(s) were not rooted (see errors above)…
- Cyclic dependency found, involving
- attempt to modify a key
- AlphaLoadMode. not supported for the Stride image format…
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/241fa0ca37b16db1.
Report an issue: GitHub.
Appendix: source
Thrown at sources/core/Stride.Core.Yaml/SortedDictionary.cs:615
{
objects[index++] = node.Item.Key;
return true;
});
}
catch (ArrayTypeMismatchException)
{
throw new ArgumentException();
}
}
}
public int Count { get { return dictionary.Count; } }
bool ICollection<TKey>.IsReadOnly { get { return true; } }
void ICollection<TKey>.Add(TKey item)
{
throw new NotSupportedException();
}
void ICollection<TKey>.Clear()
{
throw new NotSupportedException();
}
bool ICollection<TKey>.Contains(TKey item)
{
return dictionary.ContainsKey(item);
}
bool ICollection<TKey>.Remove(TKey item)
{
throw new NotSupportedException();
}
bool ICollection.IsSynchronized { get { return false; } }View on GitHub (pinned to 96fad776d2)