{"record":{"id":"aa435f896fb7a85a","repo":"stride3d/stride","slug":"cannot-copy-data-between-graphicsresources-of-types-source","errorCode":null,"errorMessage":"Cannot copy data between GraphicsResources of types [{source.GetType()}] and [{destination.GetType()}].","messagePattern":"Cannot copy data between GraphicsResources of types \\[(.+?)\\] and \\[(.+?)\\]\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs","lineNumber":1443,"sourceCode":"        {\n            ArgumentNullException.ThrowIfNull(source);\n            ArgumentNullException.ThrowIfNull(destination);\n\n            RecordDebugCounter(DebugCounterKind.Copy);\n\n            // Copy Texture -> Texture\n            if (source is Texture sourceTexture &&\n                destination is Texture destinationTexture)\n            {\n                CopyBetweenTextures(sourceTexture, destinationTexture);\n            }\n            // Copy Buffer -> Buffer\n            else if (source is Buffer sourceBuffer &&\n                     destination is Buffer destinationBuffer)\n            {\n                CopyBetweenBuffers(sourceBuffer, destinationBuffer);\n            }\n            else throw new InvalidOperationException($\"Cannot copy data between GraphicsResources of types [{source.GetType()}] and [{destination.GetType()}].\");\n\n            //\n            // Copies the data from a Texture to another Texture.\n            //\n            void CopyBetweenTextures(Texture sourceTexture, Texture destinationTexture)\n            {\n                // Get the parent Textures in case these are Texture Views\n                var sourceParent = sourceTexture.ParentTexture ?? sourceTexture;\n                var destinationParent = destinationTexture.ParentTexture ?? destinationTexture;\n\n                if (destinationTexture.Usage == GraphicsResourceUsage.Staging)\n                {\n                    // Copy staging Texture -> staging Texture\n                    if (sourceTexture.Usage == GraphicsResourceUsage.Staging)\n                    {\n                        CopyStagingTextureToStagingTexture(sourceTexture, destinationTexture);\n                    }\n                    else // Copy Texture -> staging Texture","sourceCodeStart":1425,"sourceCodeEnd":1461,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs#L1425-L1461","documentation":"CommandList.Copy(source, destination) dispatches on the concrete GraphicsResource type: Texture->Texture and Buffer->Buffer pairs are supported. When the source/destination combination matches neither branch (and no other supported pair), the method throws InvalidOperationException. Mixed or unrelated resource types cannot be copied by this API.","triggerScenarios":"Calling Copy(source, destination) where source and destination are not both Textures and not both Buffers — e.g. copying a Buffer into a Texture, a Texture into a Buffer, or between incompatible resource types.","commonSituations":"Misordered arguments (swapped source/destination of different types); assuming a generic Copy handles staging uploads across types; writing a generic resource-upload helper that passes mixed types.","solutions":["Ensure source and destination are the same resource family (both Buffer or both Texture).","For Buffer<->Texture transfers use the dedicated CopyCommandList.Copy(Buffer, Texture) / Copy(Texture, Buffer) overloads.","Fix argument order if source/destination were swapped."],"exampleFix":"// before\ncommandList.Copy(myTexture, myBuffer); // throws\n\n// after\ncommandList.CopyCommandList.Copy(myTexture, myBuffer); // dedicated Texture<->Buffer copy","handlingStrategy":"type-guard","validationCode":"if ((source is Buffer) != (destination is Buffer) && (source is Texture) != (destination is Texture))\n    throw new InvalidOperationException(\"Copy requires source and destination of the same resource type\");","typeGuard":"static bool IsCopyablePair(GraphicsResource s, GraphicsResource d) =>\n    (s is Buffer && d is Buffer) || (s is Texture && d is Texture);","tryCatchPattern":"try\n{\n    commandList.Copy(source, destination);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Cannot copy data between\"))\n{\n    // dispatch to CopyCommandList.Copy for Buffer<->Texture, or log and abort\n}","preventionTips":["Use the type-specific overloads (Copy(Texture,Texture), Copy(Buffer,Buffer)) instead of generic dispatch.","Use CopyCommandList.Copy for Buffer<->Texture transfers.","Unit-test copy helpers with every resource-type pair you support."],"tags":["direct3d12","graphics","copy","type-mismatch"],"backgroundTag":"type-mismatch","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"}