{"record":{"id":"d043c999e89addc0","repo":"stride3d/stride","slug":"an-error-occurred-while-adding-an-item-to-the-node-see-the-d043c9","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/MemberNodePresenter.cs","lineNumber":105,"sourceCode":"        }\n        catch (Exception e)\n        {\n            throw new NodePresenterException(\"An error occurred while updating the value of the node, see the inner exception for more information.\", e);\n        }\n    }\n\n    public override void AddItem(object value)\n    {\n        if (Member.Target == null || !Member.Target.IsEnumerable)\n            throw new NodePresenterException($\"{nameof(MemberNodePresenter)}.{nameof(AddItem)} cannot be invoked on members that are not collection.\");\n\n        try\n        {\n            Member.Target.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 (Member.Target == null || !Member.Target.IsEnumerable)\n            throw new NodePresenterException($\"{nameof(MemberNodePresenter)}.{nameof(AddItem)} cannot be invoked on members that are not collection.\");\n\n        try\n        {\n            Member.Target.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":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Quantum/Presenters/MemberNodePresenter.cs#L87-L123","documentation":"MemberNodePresenter.AddItem(value) wraps any exception thrown by Member.Target.Add(value) in a NodePresenterException. Member.Target is the Quantum object node of the member's collection; failures inside that Add (type mismatch, unsupported collection, reflection errors) are wrapped so the presenter layer throws a single NodePresenterException with the cause in InnerException. Callers should treat the InnerException as authoritative.","triggerScenarios":"Calling MemberNodePresenter.AddItem(value) when: the member's collection element type does not accept value, the collection is an array or read-only/fixed-size type with no Add, Member.Target exists and reports IsEnumerable but its runtime type lacks a compatible Add, or the underlying reflection helper throws.","commonSituations":"Editor 'Add item' buttons on a property whose collection was changed to an array or IReadOnlyList; dragging items of the wrong type into a list; model classes changed between Stride versions so the member's target is no longer a mutable collection.","solutions":["Catch NodePresenterException and inspect InnerException for the real failure.","Before adding, guard with the same checks the presenter uses: Member.Target != null && Member.Target.IsEnumerable, and confirm the element type is compatible with value.","Ensure the model member is declared as a mutable collection (List<T>, Dictionary<K,V>) rather than an array or IEnumerable.","Perform the add on the UI thread and on the current node instance; refresh the presenter if the member's object was replaced."],"exampleFix":"// before\nmemberPresenter.AddItem(newItem); // member is int[] -> wrapped exception\n// after\n// model change: public int[] Items  ->  public List<int> Items\nif (memberPresenter.IsEnumerable)\n    memberPresenter.AddItem(newItem);","handlingStrategy":"type-guard","validationCode":"if (memberPresenter.Member?.Target == null || !memberPresenter.IsEnumerable)\n    throw new InvalidOperationException(\"Member is not a collection.\");\nvar elementType = memberPresenter.Descriptor.GetInnerCollectionType();\nif (!elementType.IsInstanceOfType(value))\n    throw new ArgumentException($\"{value.GetType()} not assignable to element type {elementType}\");","typeGuard":"static bool CanAddToMember(MemberNodePresenter m, object value)\n    => m.Member?.Target != null\n       && m.IsEnumerable\n       && m.Descriptor.GetInnerCollectionType().IsInstanceOfType(value);","tryCatchPattern":"try\n{\n    memberPresenter.AddItem(value);\n}\ncatch (NodePresenterException ex)\n{\n    logger.Error(ex.InnerException, \"Add failed on member {Name}\", memberPresenter.Name);\n    // common causes: array/read-only target, wrong element type\n}","preventionTips":["Guard with Member.Target != null && IsEnumerable and an element-type check before every AddItem.","Declare model collection members as mutable types (List<T>, Dictionary<K,V>), never arrays or IEnumerable.","Add on the UI thread so Quantum change notifications and presenter refreshes stay consistent.","Diagnose via InnerException - the outer NodePresenterException message is generic by design."],"tags":["dotnet","stride","quantum","collection","wrapped-exception"],"backgroundTag":"unsupported-operation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}