dotnet/wpf · error · ArgumentException

SR.TextComposition_NullResultText

Error message

SR.TextComposition_NullResultText

What it means

TextComposition's constructor validates its resultText parameter and throws ArgumentException when null. WPF requires a non-null result text even when the composition produces no visible output (callers should pass an empty string instead of null).

Solutions

  1. Pass string.Empty instead of null for resultText when there is no result.
  2. Null-check or coalesce the computed text before constructing the TextComposition.
  3. If the text comes from a native call or helper, verify it returns empty string, not null, on failure.

Example fix

// before
new TextComposition(inputManager, device, null, compositionText);
// after
new TextComposition(inputManager, device, resultText ?? string.Empty, compositionText);
Defensive patterns

Strategy: validation

Validate before calling

if (resultText == null) resultText = string.Empty; // or throw your own descriptive error

Type guard

bool HasResultText(TextComposition c) => c.Text != null;

Try / catch

try { var c = new TextComposition(mgr, device, text); } catch (ArgumentException ex) { /* log param name ResultText */ }

Prevention

When it happens

Trigger: Calling the TextComposition constructor (e.g. via InputManager.CreateTextComposition or a derived class) and passing null for the resultText argument.

Common situations: Custom input/stylus/IME integration code that builds a TextComposition dynamically and computes the result text in a variable that ends up null (e.g. a lookup or conversion returned null instead of "").

Related errors


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

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextComposition.cs:103

            {
                throw new InvalidEnumArgumentException("autoComplete", 
                                                       (int)autoComplete, 
                                                       typeof(TextCompositionAutoComplete));
            }
        }

        //
        // An internal constructore to specify InputDevice directly.
        //
        internal TextComposition(InputManager inputManager, IInputElement source, string resultText, TextCompositionAutoComplete autoComplete, InputDevice inputDevice)
        {
            _inputManager = inputManager;

            _inputDevice = inputDevice;

            if (resultText == null)
            {
                throw new ArgumentException(SR.TextComposition_NullResultText);
            }

            _resultText = resultText;
            _compositionText = "";
            _systemText = "";
            _systemCompositionText = "";
            _controlText = "";

            _autoComplete = autoComplete;

            _stage = TextCompositionStage.None;

            // source of this text composition.
            _source = source;
        }

        #endregion Constructors

View on GitHub (pinned to 81131a70a4)