{"record":{"id":"b98ee21e0631bf55","repo":"dotnet/wpf","slug":"sr-textcomposition-nullresulttext","errorCode":null,"errorMessage":"SR.TextComposition_NullResultText","messagePattern":"SR\\.TextComposition_NullResultText","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextComposition.cs","lineNumber":103,"sourceCode":"            {\n                throw new InvalidEnumArgumentException(\"autoComplete\", \n                                                       (int)autoComplete, \n                                                       typeof(TextCompositionAutoComplete));\n            }\n        }\n\n        //\n        // An internal constructore to specify InputDevice directly.\n        //\n        internal TextComposition(InputManager inputManager, IInputElement source, string resultText, TextCompositionAutoComplete autoComplete, InputDevice inputDevice)\n        {\n            _inputManager = inputManager;\n\n            _inputDevice = inputDevice;\n\n            if (resultText == null)\n            {\n                throw new ArgumentException(SR.TextComposition_NullResultText);\n            }\n\n            _resultText = resultText;\n            _compositionText = \"\";\n            _systemText = \"\";\n            _systemCompositionText = \"\";\n            _controlText = \"\";\n\n            _autoComplete = autoComplete;\n\n            _stage = TextCompositionStage.None;\n\n            // source of this text composition.\n            _source = source;\n        }\n\n        #endregion Constructors\n","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/TextComposition.cs#L85-L121","documentation":"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).","triggerScenarios":"Calling the TextComposition constructor (e.g. via InputManager.CreateTextComposition or a derived class) and passing null for the resultText argument.","commonSituations":"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 \"\").","solutions":["Pass string.Empty instead of null for resultText when there is no result.","Null-check or coalesce the computed text before constructing the TextComposition.","If the text comes from a native call or helper, verify it returns empty string, not null, on failure."],"exampleFix":"// before\nnew TextComposition(inputManager, device, null, compositionText);\n// after\nnew TextComposition(inputManager, device, resultText ?? string.Empty, compositionText);","handlingStrategy":"validation","validationCode":"if (resultText == null) resultText = string.Empty; // or throw your own descriptive error","typeGuard":"bool HasResultText(TextComposition c) => c.Text != null;","tryCatchPattern":"try { var c = new TextComposition(mgr, device, text); } catch (ArgumentException ex) { /* log param name ResultText */ }","preventionTips":["Never pass null for text parameters; use string.Empty for 'no text'.","Null-coalesce computed strings before constructing input objects.","Enable nullable reference types to catch this at compile time."],"tags":["wpf","argument-null","text-composition"],"backgroundTag":"null-argument","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"}