{"record":{"id":"58d6f2023eb7aa47","repo":"dotnet/wpf","slug":"sr-initializationincomplete-glyphtypeface","errorCode":null,"errorMessage":"SR.InitializationIncomplete","messagePattern":"SR\\.InitializationIncomplete","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs","lineNumber":1677,"sourceCode":"            _initializationState = InitializationState.IsInitializing;\n        }\n\n        void ISupportInitialize.EndInit()\n        {\n            if (_initializationState != InitializationState.IsInitializing)\n            {\n                // Cannot EndInit a GlyphRun that is not being initialized.\n                throw new InvalidOperationException(SR.NotInInitialization);\n            }\n\n            Initialize(_originalUri, _styleSimulations);\n        }\n\n        private void CheckInitialized()\n        {\n            if (_initializationState != InitializationState.IsInitialized)\n            {\n                throw new InvalidOperationException(SR.InitializationIncomplete);\n            }\n        }\n\n        private void CheckInitializing()\n        {\n            if (_initializationState != InitializationState.IsInitializing)\n            {\n                throw new InvalidOperationException(SR.NotInInitialization);\n            }\n        }\n\n        /// <summary>\n        /// Allocates a GlyphIndexer for the specified accessor.\n        /// </summary>\n        private GlyphIndexer CreateGlyphIndexer(GlyphAccessor accessor)\n        {\n            GlyphIndexer indexer;\n","sourceCodeStart":1659,"sourceCodeEnd":1695,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs#L1659-L1695","documentation":"GlyphTypeface.CheckInitialized throws SR.InitializationIncomplete when an API that requires a fully initialized GlyphTypeface is used while _initializationState is not IsInitialized, i.e. construction or BeginInit/EndInit has not completed. The GlyphTypeface lazily defers font loading to EndInit, so member access before completion is an InvalidOperationException.","triggerScenarios":"Accessing GlyphTypeface members (e.g. glyph metrics, face data) after the parameterless constructor plus BeginInit but before EndInit; forgetting to call EndInit entirely; EndInit throwing (e.g. invalid font URI) leaving state incomplete; manually calling CheckInitializing/CheckInitialized-like flows around property setters that route through these guards.","commonSituations":"Using the ISupportInitialize pattern but skipping EndInit; a font file URI that makes EndInit fail silently upstream, leaving the instance unusable; code that assumes the GlyphTypeface(GlyphRun) constructor fully initializes but a code path used deferred initialization.","solutions":["Always complete the two-phase cycle: BeginInit, set UriSource/style simulations, then EndInit before using the instance.","Prefer the GlyphTypeface(Uri) constructor, which fully initializes synchronously, when deferred initialization is not needed.","Check that EndInit did not throw; catch and handle font-load failures so state is not left incomplete.","Use ISupportInitialize.IsInitialized to verify readiness before accessing members."],"exampleFix":"// before\nvar face = new GlyphTypeface();\nface.BeginInit();\nface.UriSource = fontUri;\nushort index = face.CharacterToGlyphMap['A']; // InitializationIncomplete: EndInit never called\n\n// after\nvar face = new GlyphTypeface();\nface.BeginInit();\nface.UriSource = fontUri;\nface.EndInit();\nushort index = face.CharacterToGlyphMap['A'];","handlingStrategy":"validation","validationCode":"if (!((ISupportInitialize)face).IsInitialized)\n{\n    // finish deferred init before using the face\n    ((ISupportInitialize)face).EndInit();\n}\nvar glyphIndex = face.CharacterToGlyphMap['A'];","typeGuard":"static bool IsGlyphTypefaceReady(GlyphTypeface face) => face != null && ((ISupportInitialize)face).IsInitialized;","tryCatchPattern":"try { face.EndInit(); /* then use face */ }\ncatch (InvalidOperationException) { /* deferred initialization never completed; recreate with GlyphTypeface(uri) */ }\ncatch (IOException) { /* font URI could not be loaded; validate UriSource */ }","preventionTips":["Always call EndInit before reading metrics, glyph maps, or font metadata.","Prefer the fully-initializing GlyphTypeface(Uri) constructor when deferred init is unnecessary.","Handle EndInit exceptions explicitly; a failed EndInit leaves the instance unusable.","Add debug assertions for IsInitialized in font-caching helpers."],"tags":["wpf","glyphrun","ispupportinitialize","deferred-initialization","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}