{"record":{"id":"5ce3dcef671eaccd","repo":"stride3d/stride","slug":"an-error-occurred-while-adding-an-item-to-the-node-see-the-5ce3dc","errorCode":null,"errorMessage":"An error occurred while adding an item to the node, see the inner exception for more information.","messagePattern":"An error occurred while adding an item to the node, see the inner exception for more information\\.","errorType":"exception","errorClass":"NodePresenterException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Quantum/Presenters/RootNodePresenter.cs","lineNumber":70,"sourceCode":"        }\n\n        public override void UpdateValue(object newValue)\n        {\n            throw new NodePresenterException($\"A {nameof(RootNodePresenter)} cannot have its own value updated.\");\n        }\n\n        public override void AddItem(object value)\n        {\n            if (!RootNode.IsEnumerable)\n                throw new NodePresenterException($\"{nameof(RootNodePresenter)}.{nameof(AddItem)} cannot be invoked on objects that are not collection.\");\n\n            try\n            {\n                RootNode.Add(value);\n            }\n            catch (Exception e)\n            {\n                throw new NodePresenterException(\"An error occurred while adding an item to the node, see the inner exception for more information.\", e);\n            }\n        }\n\n        public override void AddItem(object value, NodeIndex index)\n        {\n            if (!RootNode.IsEnumerable)\n                throw new NodePresenterException($\"{nameof(RootNodePresenter)}.{nameof(AddItem)} cannot be invoked on objects that are not collection.\");\n\n            try\n            {\n                RootNode.Add(value, index);\n            }\n            catch (Exception e)\n            {\n                throw new NodePresenterException(\"An error occurred while adding an item to the node, see the inner exception for more information.\", e);\n            }\n        }\n","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/RootNodePresenter.cs#L52-L88","documentation":"RootNodePresenter's nested NodeAccessor AddItem wraps RootNode.Add(value) and rethrows failures as NodePresenterException with the inner exception preserved. It means adding an item directly to the root node failed. The root cause is in the InnerException.","triggerScenarios":"Calling AddItem on the root node's accessor when RootNode.Add(value) throws — e.g. the root object is not actually a collection, or the Add on the root collection throws.","commonSituations":"Attempting to append to a root object that is not enumerable or whose collection implementation rejects the value; misuse of RootNodePresenter against a non-collection root.","solutions":["Check the InnerException for the true failure.","Ensure the root node (RootNode) is enumerable and its type supports Add.","Ensure the added value matches the root collection's element type.","Use AddItem(value, index) only on enumerable root nodes."],"exampleFix":"// before\naccessor.AddItem(newValue, NodeIndex.Empty); // throws if root is not a collection\n// after\nif (rootNode.IsEnumerable)\n    accessor.AddItem(newValue, NodeIndex.Empty);","handlingStrategy":"try-catch","validationCode":"if (rootNode == null || !rootNode.IsEnumerable)\n    throw new InvalidOperationException(\"Root node is not enumerable; AddItem will fail.\");","typeGuard":"static bool CanAddToRoot(RootNodePresenter p) => p != null && p.RootNode?.IsEnumerable == true;","tryCatchPattern":"try\n{\n    accessor.AddItem(value, index);\n}\ncatch (NodePresenterException ex)\n{\n    logger.Error(ex.InnerException, \"AddItem failed on root node\");\n}","preventionTips":["Only call AddItem on root nodes whose IsEnumerable is true.","Match the value type to the root collection's element type.","Inspect InnerException first when debugging."],"tags":["dotnet","root-node","collection","wrapped-exception"],"backgroundTag":"wrapped-exception-add-item-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}