{"record":{"id":"8de3e943af0c687d","repo":"spectreconsole/spectre.console","slug":"value-cannot-be-null-parameter-obj","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'obj')","messagePattern":"Value cannot be null\\. \\(Parameter 'obj'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Spectre.Console/IHasTreeNodes.cs","lineNumber":31,"sourceCode":"\n/// <summary>\n/// Contains extension methods for <see cref=\"IHasTreeNodes\"/>.\n/// </summary>\npublic static class HasTreeNodeExtensions\n{\n    /// <summary>\n    /// Adds a tree node.\n    /// </summary>\n    /// <typeparam name=\"T\">An object with tree nodes.</typeparam>\n    /// <param name=\"obj\">The object to add the tree node to.</param>\n    /// <param name=\"markup\">The node's markup text.</param>\n    /// <returns>The added tree node.</returns>\n    public static TreeNode AddNode<T>(this T obj, string markup)\n        where T : IHasTreeNodes\n    {\n        if (obj is null)\n        {\n            throw new ArgumentNullException(nameof(obj));\n        }\n\n        ArgumentNullException.ThrowIfNull(markup);\n\n        return AddNode(obj, new Markup(markup));\n    }\n\n    /// <summary>\n    /// Adds a tree node.\n    /// </summary>\n    /// <typeparam name=\"T\">An object with tree nodes.</typeparam>\n    /// <param name=\"obj\">The object to add the tree node to.</param>\n    /// <param name=\"renderable\">The renderable to add.</param>\n    /// <returns>The added tree node.</returns>\n    public static TreeNode AddNode<T>(this T obj, IRenderable renderable)\n        where T : IHasTreeNodes\n    {\n        if (obj is null)","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/spectreconsole/spectre.console/blob/0acc92fada6c42f13984e79c2b5f3d993bdfb099/src/Spectre.Console/IHasTreeNodes.cs#L13-L49","documentation":"Thrown by the AddNode<T>(this T obj, string markup) extension on IHasTreeNodes when obj is null. The check uses an explicit 'if (obj is null) throw new ArgumentNullException(nameof(obj))' rather than ArgumentNullException.ThrowIfNull. Because it is an extension method, the C# compiler will not surface the null as a normal instance call, so this guard exists to give a clear parameter name.","triggerScenarios":"Calling .AddNode(markup) on a null IHasTreeNodes reference (e.g. a null Tree or TreeNode variable).","commonSituations":"A Tree/TreeNode variable that was never assigned; a lookup that returned null; chaining after a method whose result was unexpectedly null.","solutions":["Ensure the Tree/TreeNode you call AddNode on is non-null before the call","Initialize the variable at declaration (e.g. var tree = new Tree(\"root\"))","Use a null check or the null-conditional operator with a fallback"],"exampleFix":"// before\nTree tree = null;\ntree.AddNode(\"item\"); // throws\n\n// after\nvar tree = new Tree(\"root\");\ntree.AddNode(\"item\");","handlingStrategy":"validation","validationCode":"if (tree is not null)\n    tree.AddNode(\"item\");","typeGuard":"static bool HasTree(T? obj) where T : IHasTreeNodes => obj is not null;","tryCatchPattern":"try\n{\n    tree.AddNode(\"item\");\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"obj\")\n{\n    // the receiver was null; initialize a new Tree and retry\n}","preventionTips":["Initialize Tree/TreeNode variables at declaration","Null-check the receiver before calling extension methods","Treat a null IHasTreeNodes as a programmer error, not a runtime condition"],"tags":["tree","null-check","argument","extension-method"],"backgroundTag":null,"analyzedSha":"0acc92fada6c42f13984e79c2b5f3d993bdfb099","analyzedAt":"2026-08-13T18:27:21.983Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}