{"record":{"id":"871254c8b27d20b8","repo":"dotnet/wpf","slug":"sr-onlyoneinitialization","errorCode":null,"errorMessage":"SR.OnlyOneInitialization","messagePattern":"SR\\.OnlyOneInitialization","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs","lineNumber":2291,"sourceCode":"            {\n                throw new NotSupportedException();\n            }\n\n            #endregion\n\n            private int _count;\n        }\n\n        #endregion Hit testing\n\n        #region ISupportInitialize interface for Xaml serialization\n\n        void ISupportInitialize.BeginInit()\n        {\n            if (IsInitialized)\n            {\n                // Cannot initialize a GlyphRun that is completely initialized.\n                throw new InvalidOperationException(SR.OnlyOneInitialization);\n            }\n\n            if (IsInitializing)\n            {\n                // Cannot initialize a GlyphRun that is already being initialized.\n                throw new InvalidOperationException(SR.InInitialization);\n            }\n\n            IsInitializing = true;\n        }\n\n        void ISupportInitialize.EndInit()\n        {\n            if (!IsInitializing)\n            {\n                // Cannot EndInit a GlyphRun that is not being initialized.\n                throw new InvalidOperationException(SR.NotInInitialization);\n            }","sourceCodeStart":2273,"sourceCodeEnd":2309,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphRun.cs#L2273-L2309","documentation":"GlyphRun implements ISupportInitialize; BeginInit() throws InvalidOperationException(SR.OnlyOneInitialization) when the GlyphRun is already fully initialized. A GlyphRun's properties can only be set during one initialization batch; after EndInit (or when constructed complete), re-initialization is disallowed.","triggerScenarios":"Calling BeginInit() on a GlyphRun where IsInitialized is true — typically calling BeginInit a second time, or on a GlyphRun created via the full constructor after EndInit has completed.","commonSituations":"XAML/baml re-initialization paths, reusing a cached GlyphRun instance for new content through ISupportInitialize, or animation/tooling code that drives BeginInit/EndInit manually.","solutions":["Create a new GlyphRun instance for each new set of properties instead of re-initializing an existing one.","Check glyphRun.IsInitialized before calling BeginInit(); skip Begin/EndInit if already initialized.","If using deferred initialization, ensure EndInit is called exactly once per BeginInit and never call Begin again afterward."],"exampleFix":"// before\nglyphRun.BeginInit(); // second pass on same instance\n// after\nvar glyphRun = new GlyphRun();\nglyphRun.BeginInit();\n// set properties...\nglyphRun.EndInit();","handlingStrategy":"validation","validationCode":"if (glyphRun.IsInitialized) { glyphRun = new GlyphRun(); }\nglyphRun.BeginInit();","typeGuard":"bool CanBeginInit(GlyphRun g) => !g.IsInitialized && !g.IsInitializing;","tryCatchPattern":"try { glyphRun.BeginInit(); }\ncatch (InvalidOperationException) { glyphRun = new GlyphRun(); glyphRun.BeginInit(); }","preventionTips":["Call BeginInit at most once per GlyphRun instance.","Check IsInitialized before driving ISupportInitialize.","Allocate a fresh GlyphRun for new content instead of re-initializing."],"tags":["wpf","glyphrun","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"}