{"record":{"id":"3ba13d2206751d94","repo":"dotnet/wpf","slug":"sr-addtext-invalid","errorCode":null,"errorMessage":"SR.AddText_Invalid","messagePattern":"SR\\.AddText_Invalid","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs","lineNumber":92,"sourceCode":"\n            Visual3D visual3D = value as Visual3D;\n\n            if (visual3D == null)\n            {\n                throw new System.ArgumentException(SR.Format(SR.Collection_BadType, this.GetType().Name, value.GetType().Name, nameof(Visual3D)));\n            }\n\n            Children.Add(visual3D);\n        }\n\n        void IAddChild.AddText(string text)\n        {\n            // The only text we accept is whitespace, which we ignore.\n            foreach (char c in text)\n            {\n                if (!Char.IsWhiteSpace(c))\n                {\n                    throw new System.InvalidOperationException(SR.Format(SR.AddText_Invalid, this.GetType().Name));\n                }\n            }\n        }\n\n        /// <summary>\n        ///     Children of this Visual3D\n        /// </summary>\n        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]\n        public Visual3DCollection Children\n        {\n            get\n            {\n                VerifyAPIReadOnly();\n\n                return _children;\n            }\n        }\n","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media3D/ModelVisual3D.cs#L74-L110","documentation":"ModelVisual3D overrides AddText (from the IAddChild pattern) and only accepts strings consisting entirely of whitespace, which it silently ignores. Any string containing a non-whitespace character causes this InvalidOperationException. Visual3D content in WPF 3D cannot be specified as text, so the type deliberately rejects AddText calls.","triggerScenarios":"Calling ModelVisual3D.AddText(string) (directly or via XAML text content) where text contains any non-whitespace character, e.g. addText(\"hello\").","commonSituations":"Putting literal text content inside a <ModelVisual3D> element in XAML (the XAML loader invokes IAddChild.AddText); copy-pasting markup patterns from 2D elements like TextBlock into 3D; generating XAML programmatically with text inside ModelVisual3D.","solutions":["Remove the text content from the ModelVisual3D element; 3D visuals have no text content.","Set content via Model property instead: assign a GeometryModel3D / Model3DGroup to ModelVisual3D.Model.","To display text in 3D, use a 3D Text (e.g. Text3D via converted Geometry from FormattedText applied to a GeometryModel3D).","If the text is only whitespace, it is ignored and no exception occurs; strip or trim non-whitespace before calling AddText."],"exampleFix":"// before\nvar v = new ModelVisual3D();\nv.AddText(\"hello\"); // InvalidOperationException\n// after\nvar v = new ModelVisual3D();\nv.Model = new GeometryModel3D(geometry, material); // use Model, not text","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(text)) throw new InvalidOperationException(\"ModelVisual3D does not accept text content; use the Model property.\"); // else safe to call AddText\nv.AddText(text);","typeGuard":"static bool CanAddText(string text) => text == null || text.All(char.IsWhiteSpace);","tryCatchPattern":"try { v.AddText(text); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"AddText\"))\n{\n    // fall back to Model-based content\n}","preventionTips":["Never put text content inside ModelVisual3D in XAML or code","Set 3D content via the Model property, not IAddChild text","Convert text to geometry (FormattedText -> Geometry -> GeometryModel3D) for 3D text"],"tags":["wpf","media3d","xaml","invalid-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}