{"record":{"id":"9673d51944373437","repo":"dotnet/wpf","slug":"block","errorCode":null,"errorMessage":"block","messagePattern":"block","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs","lineNumber":302,"sourceCode":"        /// </summary>\n        public TextFlow() \n            : base()\n        {\n            Initialize();\n        }\n\n        /// <summary>\n        /// TextFlow constructor.\n        /// </summary>\n        /// <param name=\"block\">\n        /// Block initially added to TextFlow's Blocks collection.\n        /// </param>\n        public TextFlow(Block block)\n            : base()\n        {\n            if (block == null)\n            {\n                throw new ArgumentNullException(\"block\");\n            }\n\n            Initialize();\n\n            this.Blocks.Add(block);\n        }\n\n        #endregion Constructors\n\n        //-------------------------------------------------------------------\n        //\n        //  Public Methods\n        //\n        //-------------------------------------------------------------------\n\n        #region Public Methods\n\n        /// <summary>","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextFlow.cs#L284-L320","documentation":"The TextFlow(Block) constructor throws ArgumentNullException when the caller passes a null block. The initial block added to the TextFlow's Blocks collection is a required argument; a TextFlow without any initial block should use the parameterless constructor instead.","triggerScenarios":"new TextFlow(null) or passing a Block field/property that was never assigned (e.g., a Failed binding or unset FlowDocument block).","commonSituations":"Programmatic document construction where a Paragraph/Section variable is null; XAML-load fallback paths where the block resource did not resolve; refactoring left a Block property uninitialized.","solutions":["Ensure the Block (Paragraph, Section, etc.) is created before constructing TextFlow","Add a null check or throw a descriptive error at the call site","Check why the Block reference is null (binding failure, failed resource lookup) and fix the root cause"],"exampleFix":"// before\nBlock block = FindBlock(name); // may return null\nvar flow = new TextFlow(block);\n\n// after\nBlock block = FindBlock(name) ?? new Paragraph(new Run(string.Empty));\nvar flow = new TextFlow(block);","handlingStrategy":"validation","validationCode":"if (block == null) block = new Paragraph(new Run(string.Empty));\nvar flow = new TextFlow(block);","typeGuard":"bool isUsableBlock(Block b) => b != null;","tryCatchPattern":"try { flow = new TextFlow(block); } catch (ArgumentNullException) { flow = new TextFlow(new Paragraph()); }","preventionTips":["Initialize Block references before document construction","Use null-coalescing fallbacks (?? new Paragraph()) for optional blocks","Verify XAML resource bindings resolve to real Block instances"],"tags":["wpf","argumentnull","constructor"],"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"}