{"record":{"id":"88607528e7d0f7a3","repo":"dotnet/wpf","slug":"keynotfoundexception-concurrentdictionary","errorCode":null,"errorMessage":"KeyNotFoundException","messagePattern":"KeyNotFoundException","errorType":"exception","errorClass":"KeyNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/ConcurrentDictionary.cs","lineNumber":98,"sourceCode":"                lock (_hashtable)\n                {\n                    foreach (object value in _hashtable.Values)\n                    {\n                        result.Add((V)value);\n                    }\n                }\n                return result.AsReadOnly();\n            }\n        }\n\n        public V this[K key]\n        {\n            get\n            {\n                object result = _hashtable[key];\n                if (result == null)\n                {\n                    throw new KeyNotFoundException();\n                }\n                return (V)result;\n            }\n            set\n            {\n                object val = CheckValue(value);\n                lock (_hashtable)\n                {\n                    _hashtable[key] = val;\n                }\n            }\n        }\n\n        public void Clear()\n        {\n            _hashtable.Clear();\n        }\n","sourceCodeStart":80,"sourceCodeEnd":116,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/ConcurrentDictionary.cs#L80-L116","documentation":"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.","triggerScenarios":"Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/MS/Impl/ConcurrentDictionary.cs:98 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}