stride3d/stride · error · NotSupportedException

Can't serialize a back as a

Error message

Can't serialize a {nameof(Texture)} back as a {nameof(RenderTextureDescriptor)}

What it means

RenderTextureDescriptor is a serializable description of a render texture, not a live GPU resource. During serialization Stride requires the object in this slot to be the descriptor itself; if the field actually holds a live Texture instance (deserialized via Construct, which returns new Texture()), the serializer cannot map it back and throws NotSupportedException to signal the round-trip is impossible.

Solutions

  1. Store the RenderTextureDescriptor (width/height/format/flags) in serialized fields, not a Texture instance
  2. If you need the actual texture, reference it via a Texture asset reference (Content) instead of a descriptor property
  3. Check code that overwrites the descriptor with a Texture at runtime; keep them in separate fields and exclude the Texture from serialization
  4. If creating render textures dynamically, construct a RenderTextureDescriptor from the texture's Description instead of serializing the texture

Example fix

// before
public RenderTextureDescriptor Descriptor { get; set; }
myComponent.Descriptor = someTexture; // NotSupportedException on serialize
// after
myComponent.Descriptor = new RenderTextureDescriptor(someTexture.Width, someTexture.Height, someTexture.Format, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
Defensive patterns

Strategy: validation

Validate before calling

if (value is Texture)
    throw new ArgumentException("Store a RenderTextureDescriptor here, not a Texture instance.");

Type guard

bool IsDescriptor(object o) => o is RenderTextureDescriptor && o is not Texture;

Try / catch

try
{
    serializer.Serialize(stream, descriptor);
}
catch (NotSupportedException)
{
    // rebuild descriptor from texture
    descriptor = new RenderTextureDescriptor(tex.Width, tex.Height, tex.Format, TextureFlags.ShaderResource);
}

Prevention

When it happens

Trigger: Assigning a loaded/instantiated Texture object to a property or field declared as RenderTextureDescriptor (or to a RenderTexture's descriptor slot) and then serializing it; e.g. code that fetches a Texture from a content manager or GraphicsDevice and stores it where the descriptor was expected.

Common situations: Confusing Texture with RenderTextureDescriptor when wiring up render textures in scenes; editor code replacing a descriptor with a runtime-created texture; custom entity components that keep a Texture reference but are serialized as descriptors.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Rendering/Rendering/RenderTextures/RenderTextureDescriptor.cs:95

                        break;
                    case RenderTextureFormat.HDR:
                        pixelFormat = PixelFormat.R16G16B16A16_Float;
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                // Find color space
                // If linear, use sRGB
                if (renderTextureDescriptor.ColorSpace == ColorSpace.Linear)
                    pixelFormat = pixelFormat.ToSRgb();

                var textureDescription = TextureDescription.New2D(renderTextureDescriptor.Width, renderTextureDescriptor.Height, pixelFormat, TextureFlags.ShaderResource | TextureFlags.RenderTarget);
                texture.InitializeFrom(textureDescription, new TextureViewDescription());
            }
            else
            {
                throw new NotSupportedException($"Can't serialize a {nameof(Texture)} back as a {nameof(RenderTextureDescriptor)}");
            }
        }

        public override object Construct(ContentSerializerContext context)
        {
            return new Texture();
        }
    }
}

View on GitHub (pinned to 96fad776d2)