dotnet/wpf · error · ArgumentException
SR.Format(SR.TextCompositionManager_NoInputManager…
Error message
SR.Format(SR.TextCompositionManager_NoInputManager, "composition")
What it means
TextCompositionManager.UnsafeStartComposition throws ArgumentException when the composition was not created with/attached to an InputManager (composition._InputManager is null). The manager needs the InputManager to route the composition events through the input pipeline.
Solutions
- Create the composition via InputManager.Current.CreateTextComposition(device) so the InputManager is set.
- Ensure the inputManager argument passed to the TextComposition constructor is non-null.
- If testing, use InputManager.Current rather than a null or detached InputManager.
Example fix
// before
var composition = new TextComposition(null, device, "");
TextCompositionManager.StartComposition(composition);
// after
var composition = InputManager.Current.CreateTextComposition(device);
composition.SetText("");
TextCompositionManager.StartComposition(composition); Defensive patterns
Strategy: validation
Validate before calling
if (composition.InputManager == null) throw new InvalidOperationException("Create the composition via InputManager.Current.CreateTextComposition first."); Type guard
static bool CanStart(TextComposition c) => c?.Stage == TextCompositionStage.None;
Try / catch
try { TextCompositionManager.StartComposition(composition); } catch (ArgumentException ex) { /* composition not attached to an InputManager */ } Prevention
- Always use InputManager.Current.CreateTextComposition to build compositions.
- Never construct TextComposition with a null inputManager argument.
- Keep composition creation and usage on the same dispatcher/thread.
When it happens
Trigger: Calling TextCompositionManager.StartComposition (or triggering it via PreProcessInput/PostProcessInput) with a TextComposition whose InputManager is null — typically one constructed directly with a null inputManager argument.
Common situations: Constructing a TextComposition manually with new TextComposition(null, device, text) instead of via InputManager.CreateTextComposition, then passing it to StartComposition.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- SR.Format(SR.TextCompositionManager_TextCompositionHasStarte…
- SR.Format(SR.TextCompositionManager_TextCompositionNotStarte…
- SR.Format(SR.TextCompositionManager_TextCompositionHasDone…
- SR.TextComposition_NullResultText
- " }} " element found. Expected fixed page element ( }} ).
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/ce2a17db3b3fceda.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs:314
//------------------------------------------------------
//
// Internal Events
//
//------------------------------------------------------
//------------------------------------------------------
//
// Private Methods
//
//------------------------------------------------------
private static bool UnsafeStartComposition(TextComposition composition)
{
ArgumentNullException.ThrowIfNull(composition);
if (composition._InputManager == null)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, "composition"));
}
if (composition.Stage != TextCompositionStage.None)
{
throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasStarted, "composition"));
}
composition.Stage = TextCompositionStage.Started;
TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition)
{
RoutedEvent = TextCompositionManager.PreviewTextInputStartEvent,
Source = composition.Source
};
return composition._InputManager.ProcessInput(textargs);
}
private static bool UnsafeUpdateComposition(TextComposition composition)
{View on GitHub (pinned to 81131a70a4)