{"record":{"id":"cab2e90c6dfccf87","repo":"stride3d/stride","slug":"unknown-resource-type","errorCode":null,"errorMessage":"Unknown resource type","messagePattern":"Unknown resource type","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs","lineNumber":1926,"sourceCode":"        /// <summary>\n        ///   Copies data from memory to a sub-resource created in non-mappable memory.\n        /// </summary>\n        /// <param name=\"resource\">The destination Graphics Resource to copy data to.</param>\n        /// <param name=\"subResourceIndex\">The sub-resource index of <paramref name=\"resource\"/> to copy data to.</param>\n        /// <param name=\"sourceData\">The source data in CPU memory to copy.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"resource\"/> is <see langword=\"null\"/>.</exception>\n        /// <exception cref=\"InvalidOperationException\">\n        ///   Only <see cref=\"Texture\"/>s and <see cref=\"Buffer\"/>s are supported.\n        /// </exception>\n        /// <inheritdoc cref=\"UpdateSubResource(GraphicsResource, int, ReadOnlySpan{byte})\" path=\"/remarks\" />\n        internal void UpdateSubResource(GraphicsResource resource, int subResourceIndex, DataBox sourceData)\n        {\n            ResourceRegion region = resource switch\n            {\n                Texture texture => new ResourceRegion(left: 0, top: 0, front: 0, texture.Width, texture.Height, texture.Depth),\n                Buffer buffer => new ResourceRegion(left: 0, top: 0, front: 0, buffer.SizeInBytes, bottom: 1, back: 1),\n\n                _ => throw new InvalidOperationException(\"Unknown resource type\")\n            };\n\n            UpdateSubResource(resource, subResourceIndex, sourceData, region);\n        }\n\n        /// <summary>\n        ///   Copies data from memory to a sub-resource created in non-mappable memory.\n        /// </summary>\n        /// <param name=\"resource\">The destination Graphics Resource to copy data to.</param>\n        /// <param name=\"subResourceIndex\">The sub-resource index of <paramref name=\"resource\"/> to copy data to.</param>\n        /// <param name=\"sourceData\">The source data in CPU memory to copy.</param>\n        /// <param name=\"region\">\n        ///   <para>\n        ///     A <see cref=\"ResourceRegion\"/> that defines the portion of the destination sub-resource to copy the resource data into.\n        ///     Coordinates are in bytes for Buffers and in texels for Textures.\n        ///     The dimensions of the source must fit the destination.\n        ///   </para>\n        ///   <para>","sourceCodeStart":1908,"sourceCodeEnd":1944,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs#L1908-L1944","documentation":"UpdateSubresource builds a full-size ResourceRegion by pattern-matching the resource against Texture and Buffer. Any other GraphicsResource-derived type (or null outside those cases) falls to the discard arm and throws InvalidOperationException('Unknown resource type').","triggerScenarios":"Calling CommandList.UpdateSubresource (or the overload that computes the region) with a resource that is neither Texture nor Buffer, e.g. a custom GraphicsResource subclass or a null/other resource on the Direct3D12 backend.","commonSituations":"Passing a QueryPool, custom resource wrapper, or wrong-typed variable to UpdateSubresource; refactor introduced a new resource kind not handled by the switch.","solutions":["Ensure the resource passed is a Texture or Buffer instance.","If a new resource type was added, extend the switch expression to map it to a ResourceRegion.","Verify with a type check before the call and route other resource kinds to the appropriate update API.","Null-check the resource; a null fails the type patterns and lands in the discard arm."],"exampleFix":"// before\ncommandList.UpdateSubresource(customResource, 0, data); // throws\n// after\nif (resource is Texture t) commandList.UpdateSubresource(t, 0, data);\nelse if (resource is Buffer b) commandList.UpdateSubresource(b, 0, data);","handlingStrategy":"type-guard","validationCode":"if (resource is not Texture && resource is not Buffer)\n    throw new ArgumentException(\"UpdateSubresource requires Texture or Buffer\", nameof(resource));","typeGuard":"static bool IsUpdatable(GraphicsResource r) => r is Texture or Buffer;","tryCatchPattern":"try { commandList.UpdateSubresource(resource, 0, data); }\ncatch (InvalidOperationException ex) { log.Error(\"Unsupported resource type for update\", ex); }","preventionTips":["Only pass Texture or Buffer to UpdateSubresource.","Null-check resources forwarded from generic helpers.","Extend the switch when adding new resource kinds."],"tags":["direct3d12","graphics","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"}