dotnet/wpf · error · KeyNotFoundException
KeyNotFoundException
Error message
KeyNotFoundException
What it means
The internal XAML ConcurrentDictionary indexer throws KeyNotFoundException when the key is absent from the underlying hashtable (a null value means the slot is empty). This mirrors Dictionary<K,V> semantics: readers must ensure the key exists or use TryGetValue instead of the indexer.
Solutions
- Call TryGetValue instead of the indexer when the key may be absent
- Ensure the key is added (Add or indexer set) before reading it
- Catch KeyNotFoundException around the indexer access
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/ConcurrentDictionary.cs:98 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/88607528e7d0f7a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/ConcurrentDictionary.cs:98
lock (_hashtable)
{
foreach (object value in _hashtable.Values)
{
result.Add((V)value);
}
}
return result.AsReadOnly();
}
}
public V this[K key]
{
get
{
object result = _hashtable[key];
if (result == null)
{
throw new KeyNotFoundException();
}
return (V)result;
}
set
{
object val = CheckValue(value);
lock (_hashtable)
{
_hashtable[key] = val;
}
}
}
public void Clear()
{
_hashtable.Clear();
}
View on GitHub (pinned to 81131a70a4)