stride3d/stride · error · InvalidOperationException

Unknown type of Graphics Resource

Error message

Unknown type of Graphics Resource

What it means

CommandList.Update dispatches based on resource type: it calls UpdateTexture for Texture and UpdateBuffer for Buffer. Any other GraphicsResource type hits the else and throws InvalidOperationException('Unknown type of Graphics Resource').

Solutions

  1. Only call Update with Texture or Buffer instances.
  2. For other resource kinds, use their dedicated update/upload API instead of the generic Update.
  3. If a custom resource type is required, implement the upload path yourself (e.g. staging buffer + CopyResource) rather than routing through Update.
  4. Null-check before calling: null also fails both type tests.

Example fix

// before
commandList.Update(myCustomResource, data); // throws
// after
if (myResource is Texture tex) commandList.Update(tex, data);
else if (myResource is Buffer buf) commandList.Update(buf, data);
Defensive patterns

Strategy: type-guard

Validate before calling

if (resource is not Texture && resource is not Buffer)
    throw new ArgumentException("Update requires Texture or Buffer", nameof(resource));

Type guard

static bool CanUpdate(GraphicsResource r) => r is Texture or Buffer;

Try / catch

try { commandList.Update(resource, data); }
catch (InvalidOperationException ex) { log.Error("Update: unsupported resource type", ex); }

Prevention

When it happens

Trigger: Calling CommandList.Update(resource, sourceData, ...) with a resource that is neither Texture nor Buffer on the Direct3D12 backend, including custom GraphicsResource subclasses.

Common situations: Updating a query pool, custom GPU resource, or accidentally passing the wrong object; code refactors where a new resource type was introduced but Update wasn't extended.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/3970636bf8afaf80. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs:2004

        ///   </para>
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="resource"/> is <see langword="null"/>.</exception
        /// <exception cref="ArgumentOutOfRangeException">
        ///   <paramref name="resource"/> is a <see cref="Texture"/>, but its <see cref="Texture.Dimension"/> is not one of the supported types.
        /// </exception
        /// <exception cref="InvalidOperationException"><paramref name="resource"/> is of an unknown type and cannot be updated.</exception>
        /// <inheritdoc cref="UpdateSubResource(GraphicsResource, int, ReadOnlySpan{byte}, ResourceRegion)" path="/remarks" />
        internal unsafe partial void UpdateSubResource(GraphicsResource resource, int subResourceIndex, DataBox sourceData, ResourceRegion region)
        {
            if (resource is Texture texture)
            {
                UpdateTexture(texture);
            }
            else if (resource is Buffer)
            {
                UpdateBuffer();
            }
            else throw new InvalidOperationException("Unknown type of Graphics Resource");

            //
            // Updates a Texture with data from CPU memory.
            //
            void UpdateTexture(Texture texture)
            {
                var width = region.Right - region.Left;
                var height = region.Bottom - region.Top;
                var depth = region.Back - region.Front;

                SkipInit(out ResourceDesc resourceDescription);
                switch (texture.Dimension)
                {
                    case TextureDimension.Texture1D:
                        resourceDescription = texture.ConvertToNativeDescription1D();
                        resourceDescription.Width = (ulong) width;
                        resourceDescription.DepthOrArraySize = 1;
                        resourceDescription.MipLevels = 1;

View on GitHub (pinned to 96fad776d2)