{"record":{"id":"ce2a17db3b3fceda","repo":"dotnet/wpf","slug":"sr-format-sr-textcompositionmanager-noinputmanager","errorCode":null,"errorMessage":"SR.Format(SR.TextCompositionManager_NoInputManager, \"composition\")","messagePattern":"SR\\.Format\\(SR\\.TextCompositionManager_NoInputManager, \"composition\"\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs","lineNumber":314,"sourceCode":"        //------------------------------------------------------\n        //\n        //  Internal Events\n        //\n        //------------------------------------------------------\n\n        //------------------------------------------------------\n        //\n        //  Private Methods\n        //\n        //------------------------------------------------------\n\n        private static bool UnsafeStartComposition(TextComposition composition)\n        {\n            ArgumentNullException.ThrowIfNull(composition);\n\n            if (composition._InputManager == null)\n            {\n                throw new ArgumentException(SR.Format(SR.TextCompositionManager_NoInputManager, \"composition\"));\n            }\n\n            if (composition.Stage != TextCompositionStage.None)\n            {\n                throw new ArgumentException(SR.Format(SR.TextCompositionManager_TextCompositionHasStarted, \"composition\"));\n            }\n\n            composition.Stage = TextCompositionStage.Started;\n            TextCompositionEventArgs textargs = new TextCompositionEventArgs(composition._InputDevice, composition)\n            {\n                RoutedEvent = TextCompositionManager.PreviewTextInputStartEvent,\n                Source = composition.Source\n            };\n            return composition._InputManager.ProcessInput(textargs);\n        }\n\n        private static bool UnsafeUpdateComposition(TextComposition composition)\n        {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextCompositionManager.cs#L296-L332","documentation":"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.","triggerScenarios":"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.","commonSituations":"Constructing a TextComposition manually with new TextComposition(null, device, text) instead of via InputManager.CreateTextComposition, then passing it to StartComposition.","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."],"exampleFix":"// before\nvar composition = new TextComposition(null, device, \"\");\nTextCompositionManager.StartComposition(composition);\n// after\nvar composition = InputManager.Current.CreateTextComposition(device);\ncomposition.SetText(\"\");\nTextCompositionManager.StartComposition(composition);","handlingStrategy":"validation","validationCode":"if (composition.InputManager == null) throw new InvalidOperationException(\"Create the composition via InputManager.Current.CreateTextComposition first.\");","typeGuard":"static bool CanStart(TextComposition c) => c?.Stage == TextCompositionStage.None;","tryCatchPattern":"try { TextCompositionManager.StartComposition(composition); } catch (ArgumentException ex) { /* composition not attached to an InputManager */ }","preventionTips":["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."],"tags":["wpf","text-composition","input-manager"],"backgroundTag":"invalid-argument-value","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"}