dotnet/wpf · error · InvalidOperationException

SR.InitializationIncomplete

Error message

SR.InitializationIncomplete

What it means

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.

Solutions

  1. Always complete the two-phase cycle: BeginInit, set UriSource/style simulations, then EndInit before using the instance.
  2. Prefer the GlyphTypeface(Uri) constructor, which fully initializes synchronously, when deferred initialization is not needed.
  3. Check that EndInit did not throw; catch and handle font-load failures so state is not left incomplete.
  4. Use ISupportInitialize.IsInitialized to verify readiness before accessing members.

Example fix

// before
var face = new GlyphTypeface();
face.BeginInit();
face.UriSource = fontUri;
ushort index = face.CharacterToGlyphMap['A']; // InitializationIncomplete: EndInit never called

// after
var face = new GlyphTypeface();
face.BeginInit();
face.UriSource = fontUri;
face.EndInit();
ushort index = face.CharacterToGlyphMap['A'];
Defensive patterns

Strategy: validation

Validate before calling

if (!((ISupportInitialize)face).IsInitialized)
{
    // finish deferred init before using the face
    ((ISupportInitialize)face).EndInit();
}
var glyphIndex = face.CharacterToGlyphMap['A'];

Type guard

static bool IsGlyphTypefaceReady(GlyphTypeface face) => face != null && ((ISupportInitialize)face).IsInitialized;

Try / catch

try { face.EndInit(); /* then use face */ }
catch (InvalidOperationException) { /* deferred initialization never completed; recreate with GlyphTypeface(uri) */ }
catch (IOException) { /* font URI could not be loaded; validate UriSource */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/58d6f2023eb7aa47. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/GlyphTypeface.cs:1677

            _initializationState = InitializationState.IsInitializing;
        }

        void ISupportInitialize.EndInit()
        {
            if (_initializationState != InitializationState.IsInitializing)
            {
                // Cannot EndInit a GlyphRun that is not being initialized.
                throw new InvalidOperationException(SR.NotInInitialization);
            }

            Initialize(_originalUri, _styleSimulations);
        }

        private void CheckInitialized()
        {
            if (_initializationState != InitializationState.IsInitialized)
            {
                throw new InvalidOperationException(SR.InitializationIncomplete);
            }
        }

        private void CheckInitializing()
        {
            if (_initializationState != InitializationState.IsInitializing)
            {
                throw new InvalidOperationException(SR.NotInInitialization);
            }
        }

        /// <summary>
        /// Allocates a GlyphIndexer for the specified accessor.
        /// </summary>
        private GlyphIndexer CreateGlyphIndexer(GlyphAccessor accessor)
        {
            GlyphIndexer indexer;

View on GitHub (pinned to 81131a70a4)