{"record":{"id":"c3c7c4ef32b68089","repo":"dotnet/wpf","slug":"initializationstate","errorCode":null,"errorMessage":"InitializationState != ","messagePattern":"InitializationState != ","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs","lineNumber":243,"sourceCode":"                set { _zStream.nextOut = value; }\n            }\n\n            public uint AvailOut\n            {\n                get { return _zStream.availOut; }\n                set { _zStream.availOut = value; }\n            }\n\n            private void EnsureNotDisposed()\n            {\n                ObjectDisposedException.ThrowIf(InitializationState == State.Disposed, this);\n            }\n\n\n            private void EnsureState(State requiredState)\n            {\n                if (InitializationState != requiredState)\n                    throw new InvalidOperationException(\"InitializationState != \" + requiredState.ToString());\n            }\n\n\n            public ErrorCode DeflateInit2_(CompressionLevel level, int windowBits, int memLevel, CompressionStrategy strategy)\n            {\n                EnsureNotDisposed();\n                EnsureState(State.NotInitialized);\n\n                ErrorCode errC = Interop.Zlib.DeflateInit2_(ref _zStream, level, CompressionMethod.Deflated, windowBits, memLevel, strategy);\n                _initializationState = State.InitializedForDeflate;\n\n                return errC;\n            }\n\n\n            public ErrorCode Deflate(FlushCode flush)\n            {\n                EnsureNotDisposed();","sourceCodeStart":225,"sourceCodeEnd":261,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Common/src/System/IO/Compression/DeflateZLib/ZLibNative.cs#L225-L261","documentation":"System.Xaml's internal ConcurrentDictionary<K,V> throws KeyNotFoundException when the indexer getter is called with a key that is not present in the underlying hashtable. Unlike Dictionary<K,V>, this lightweight internal implementation has no TryGetValue, so a missing key is always a hard exception.","triggerScenarios":"Reading dict[key] where key was never added (or was added by another thread that has not yet published the value); the getter does obj result = _hashtable[key] and throws when result == null.","commonSituations":"XAML type/schema lookups where a namespace or assembly mapping was never registered; races where code assumes a key exists because a related API returned successfully; reflection over assemblies lacking the expected xmlns mapping.","solutions":["Verify the key actually exists before indexing; add it first if this is your own code path (use ContainsKey or the TryGetValue/Add members if available).","For XamlSchemaContext/xmlns lookup failures, ensure the assembly carries correct XmlnsDefinition attributes and that InternalsVisibleTo entries are intact.","If a race is suspected, synchronize the write of the key before any reader dereferences it, or retry the lookup after initialization completes.","If this originates inside System.Xaml itself, capture the missing key value and file a WPF issue; there is no TryGetValue fallback in this internal type."],"exampleFix":"// before\nvar clrNs = nsMap[xmlNs]; // KeyNotFoundException if absent\n// after\nif (nsMap.ContainsKey(xmlNs))\n{\n    var clrNs = nsMap[xmlNs];\n}\nelse\n{\n    // register or skip\n}","handlingStrategy":"validation","validationCode":"// see 4850","typeGuard":null,"tryCatchPattern":null,"preventionTips":["entry 0 unused"],"tags":["key-not-found","dictionary","wpf","xaml"],"backgroundTag":"resource-not-found","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"}