{"record":{"id":"89d21ad926fd8117","repo":"stride3d/stride","slug":"argumentnullexception-pasteresultitem","errorCode":null,"errorMessage":"ArgumentNullException: pasteResultItem","messagePattern":"ArgumentNullException: pasteResultItem","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/ViewModel/CopyPasteProcessors/UIHierarchyPasteProcessor.cs","lineNumber":23,"sourceCode":"using System.Threading.Tasks;\nusing Stride.Core.Assets;\nusing Stride.Core.Assets.Editor.Services;\nusing Stride.Core.Assets.Editor.ViewModel.CopyPasteProcessors;\nusing Stride.Core.Assets.Quantum;\nusing Stride.Core;\nusing Stride.Core.Quantum;\nusing Stride.Assets.Quantum;\nusing Stride.Assets.UI;\nusing Stride.UI;\nusing Stride.UI.Panels;\n\nnamespace Stride.Assets.Presentation.ViewModel.CopyPasteProcessors\n{\n    public class UIHierarchyPasteProcessor : AssetCompositeHierarchyPasteProcessor<UIElementDesign, UIElement>\n    {\n        public override Task Paste(IPasteItem pasteResultItem, AssetPropertyGraph assetPropertyGraph, ref NodeAccessor nodeAccessor, ref PropertyContainer container)\n        {\n            if (pasteResultItem == null) throw new ArgumentNullException(nameof(pasteResultItem));\n\n            var propertyGraph = (UIAssetPropertyGraph)assetPropertyGraph;\n            var parentElement = nodeAccessor.RetrieveValue() as UIElement;\n\n            // 1. try to paste as hierarchy\n            var hierarchy = pasteResultItem.Data as AssetCompositeHierarchyData<UIElementDesign, UIElement>;\n            if (hierarchy != null)\n            {\n                // Note: check that adding or inserting is supported is done in CanPaste()\n                foreach (var rootUIElement in hierarchy.RootParts)\n                {\n                    var asset = (UIAssetBase)propertyGraph.Asset;\n                    var insertIndex = parentElement == null ? asset.Hierarchy.RootParts.Count : ((parentElement as Panel)?.Children.Count ?? 0);\n                    propertyGraph.AddPartToAsset(hierarchy.Parts, hierarchy.Parts[rootUIElement.Id], parentElement, insertIndex);\n                }\n            }\n            return Task.CompletedTask;\n        }","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/ViewModel/CopyPasteProcessors/UIHierarchyPasteProcessor.cs#L5-L41","documentation":"Argument-null validation guard in UIHierarchyPasteProcessor.Paste: the pasteResultItem parameter is null when the paste operation is invoked. The processor needs a valid paste item to build the pasted UI element hierarchy; a null item means no content was actually pasted, so the operation is rejected immediately.","triggerScenarios":"Invoking the paste pipeline on a UI asset with a null IPasteItem — typically a null result from an upstream copy/clone step passed straight into Paste.","commonSituations":"Custom copy-paste processors or editor automation that call Paste directly with the result of a failed/absent copy operation; clipboard API returning null on empty paste buffer.","solutions":["Ensure the copy/clone step produced a non-null IPasteItem before invoking Paste","Guard the call site: skip paste (or show a message) when the paste item is null","If using the built-in pipeline, confirm the clipboard actually contains copied UI elements before triggering paste"],"exampleFix":"// before\nawait processor.Paste(copiedItem, graph, ref accessor, ref container); // copiedItem may be null\n// after\nif (copiedItem != null)\n    await processor.Paste(copiedItem, graph, ref accessor, ref container);","handlingStrategy":"type-guard","validationCode":"if (pasteItem == null) return; // nothing to paste","typeGuard":"bool CanPaste(IPasteItem item) => item?.Data != null;","tryCatchPattern":"try { await processor.Paste(item, graph, ref accessor, ref container); }\ncatch (ArgumentNullException) { // clipboard was empty; show 'nothing to paste' feedback\n}","preventionTips":["Check clipboard/clone result is non-null before invoking paste processors","Unit-test the copy->paste round trip for custom processors","Disable paste UI actions when the copy buffer is empty"],"tags":["stride","editor","clipboard"],"backgroundTag":"null-argument","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"}