stride3d/stride · error · InvalidOperationException

Trying to serialize a Texture without CPU info.

Error message

Trying to serialize a Texture without CPU info.

What it means

Serializing a live Texture object requires CPU-side data (Texture.GetSerializationData, i.e. TextureDescription plus staging data). Textures created without CPU-side serialization info (e.g. render targets, GPU-only textures, textures created from pointers) return null, so Serialize throws this InvalidOperationException. The library simply cannot write GPU-resident-only texture state to the stream.

Solutions

  1. Serialize only textures that were loaded/created with CPU-side data (asset textures), not render targets.
  2. If the texture must be saved, load it into a staging texture that retains serialization data first.
  3. Guard with texture.GetSerializationData() != null before serializing and skip or substitute a placeholder.
  4. Mark such textures as non-serializable so the content pipeline excludes them.

Example fix

// before
serializer.Serialize(stream, renderTargetTexture);
// after
if (renderTargetTexture.GetSerializationData() == null)
    throw new NotSupportedException("Texture has no CPU-side serialization data; load from an asset instead.");
serializer.Serialize(stream, renderTargetTexture);
Defensive patterns

Strategy: validation

Validate before calling

if (texture.GetSerializationData() == null)
    throw new NotSupportedException($"Texture {texture.Name} has no CPU-side serialization data and cannot be saved.");

Type guard

bool IsSerializableTexture(Texture t) => t.GetSerializationData() != null;

Try / catch

try
{
    serializer.Serialize(stream, texture);
}
catch (InvalidOperationException ex)
{
    log.Warn(ex, "Skipping non-serializable (GPU-only) texture");
    // exclude texture or save a placeholder
}

Prevention

When it happens

Trigger: Calling TextureContentSerializer.Serialize with a Texture that was created without serialization data, such as a render target or a texture initialized from raw memory with CPU info not retained.

Common situations: Trying to save a scene/prefab snapshot containing a render target or dynamically created GPU texture; serialization code that captures textures bound for rendering; debug tooling dumping live framebuffers instead of loaded assets.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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

Appendix: source

Thrown at sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs:129

                        // Load initial texture and discard it (we are going to load the full chunk texture right after)
                        if (storageHeader.InitialImage)
                        {
                            using (var textureData = Image.Load(stream.UnderlyingStream))
                            {
                            }
                        }

                        // Deserialize whole texture without streaming feature
                        var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);
                        DeserializeTexture(contentSerializerContext.ContentManager, texture, ref imageDescription, ref storageHeader);
                    }
                }
            }
            else
            {
                var textureData = texture.GetSerializationData();
                if (textureData == null)
                    throw new InvalidOperationException("Trying to serialize a Texture without CPU info.");

                textureData.Write(stream);
            }
        }

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

        private static void DeserializeTexture(ContentManager contentManager, Texture texture, ref ImageDescription imageDescription, ref ContentStorageHeader storageHeader)
        {
            using (var content = new ContentStreamingService())
            {
                // Get content storage container
                var storage = content.GetStorage(ref storageHeader);
                if (storage == null)
                    throw new ContentStreamingException("Missing content storage.");

View on GitHub (pinned to 96fad776d2)