{"record":{"id":"cdc00fabe114bcf7","repo":"dotnet/wpf","slug":"sr-initializationincomplete","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/GlyphRun.cs","lineNumber":2344,"sourceCode":"                (_glyphOffsets == null ? null : ((_textFormattingMode != TextFormattingMode.Ideal) ? (IList<Point>)(new List<Point>()) : (IList<Point>)(new ThousandthOfEmRealPoints(_renderingEmSize, _glyphOffsets)))),\n                _characters,\n                _deviceFontName,\n                _clusterMap,\n                _caretStops,\n                _language,\n                TextFormattingMode.Ideal\n                );\n\n            // User should be able to fix errors that are only caught at EndInit() time. So set Initializing flag to\n            // false after Initialization succeeds.\n            IsInitializing = false;\n        }\n\n        private void CheckInitialized()\n        {\n            if (!IsInitialized)\n            {\n                throw new InvalidOperationException(SR.InitializationIncomplete);\n            }\n\n            // Ensure the bits are set consistently. The object cannot be in both states.\n            Debug.Assert(!IsInitializing);\n        }\n\n        private void CheckInitializing()\n        {\n            if (!IsInitializing)\n            {\n                throw new InvalidOperationException(SR.NotInInitialization);\n            }\n\n            // Ensure the bits are set consistently. The object cannot be in both states.\n            Debug.Assert(!IsInitialized);\n        }\n\n        private bool IsInitializing","sourceCodeStart":2326,"sourceCodeEnd":2362,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs#L2326-L2362","documentation":"CheckInitialized() is the gate GlyphRun uses before consuming its properties: it throws InvalidOperationException(SR.InitializationIncomplete) when the object was begun with BeginInit (initializing state) but EndInit() has not completed, so the glyph arrays and related fields were never validated and committed. The library throws it because using a half-initialized GlyphRun would produce inconsistent glyph data downstream.","triggerScenarios":"Reading GlyphRun properties or calling APIs that call CheckInitialized (e.g. computing metrics, drawing, ToGeometry) after BeginInit() but before EndInit(), or when EndInit was never called because property setting threw earlier.","commonSituations":"Exception during property assignment inside the init block leaves the object still 'initializing'; code that accesses the GlyphRun from another thread or callback before the XAML loader finished EndInit; skipping EndInit because a property appeared optional.","solutions":["Complete the initialization sequence: call EndInit() after setting all required properties inside a BeginInit/EndInit pair.","If a property-set exception aborted initialization, wrap the whole BeginInit..EndInit block in try/catch and discard/recreate the GlyphRun on failure.","Verify all required GlyphRun properties (GlyphTypeface, FontRenderingEmSize, GlyphIndices, AdvanceWidths, etc.) are set before EndInit, since a throw inside the block leaves it incomplete."],"exampleFix":"// before\nvar run = new GlyphRun();\n((ISupportInitialize)run).BeginInit();\nrun.GlyphIndices = indices;\nDraw(run); // throws: initialization incomplete, EndInit never called\n\n// after\nvar run = new GlyphRun();\n((ISupportInitialize)run).BeginInit();\nrun.GlyphIndices = indices;\nrun.AdvanceWidths = widths;\n((ISupportInitialize)run).EndInit();\nDraw(run);","handlingStrategy":"try-catch","validationCode":"static bool IsGlyphRunReady(GlyphRun run) =>\n    run != null && run.GlyphIndices != null && run.AdvanceWidths != null && run.GlyphTypeface != null;\n// use before consuming the run; only true after EndInit completed","typeGuard":"static bool IsUsable(GlyphRun? run) =>\n    run is not null && run.GlyphIndices is { Length: > 0 } && run.AdvanceWidths is { Length: > 0 };","tryCatchPattern":"try\n{\n    UseGlyphRun(run); // metrics, drawing, etc.\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Initialization\"))\n{\n    // finish initialization or rebuild the GlyphRun before retrying\n}","preventionTips":["Keep the BeginInit..EndInit block contiguous; never return or await between them without a finally that completes or discards.","Set all required properties before EndInit so no exception aborts the commit.","Do not share a partially initialized GlyphRun across threads or expose it from a factory until EndInit has run."],"tags":["wpf","glyphrun","initialization","invalid-state-transition","partial-initialization"],"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-21T21:30:21.729Z"}