{"record":{"id":"2af8729b7a5c02fa","repo":"stride3d/stride","slug":"trying-to-serialize-a-texture-without-cpu-info","errorCode":null,"errorMessage":"Trying to serialize a Texture without CPU info.","messagePattern":"Trying to serialize a Texture without CPU info\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs","lineNumber":129,"sourceCode":"                        // Load initial texture and discard it (we are going to load the full chunk texture right after)\n                        if (storageHeader.InitialImage)\n                        {\n                            using (var textureData = Image.Load(stream.UnderlyingStream))\n                            {\n                            }\n                        }\n\n                        // Deserialize whole texture without streaming feature\n                        var contentSerializerContext = stream.Context.Get(ContentSerializerContext.ContentSerializerContextProperty);\n                        DeserializeTexture(contentSerializerContext.ContentManager, texture, ref imageDescription, ref storageHeader);\n                    }\n                }\n            }\n            else\n            {\n                var textureData = texture.GetSerializationData();\n                if (textureData == null)\n                    throw new InvalidOperationException(\"Trying to serialize a Texture without CPU info.\");\n\n                textureData.Write(stream);\n            }\n        }\n\n        public override object Construct(ContentSerializerContext context)\n        {\n            return new Texture();\n        }\n\n        private static void DeserializeTexture(ContentManager contentManager, Texture texture, ref ImageDescription imageDescription, ref ContentStorageHeader storageHeader)\n        {\n            using (var content = new ContentStreamingService())\n            {\n                // Get content storage container\n                var storage = content.GetStorage(ref storageHeader);\n                if (storage == null)\n                    throw new ContentStreamingException(\"Missing content storage.\");","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Data/TextureContentSerializer.cs#L111-L147","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Serialize only textures that were loaded/created with CPU-side data (asset textures), not render targets.","If the texture must be saved, load it into a staging texture that retains serialization data first.","Guard with texture.GetSerializationData() != null before serializing and skip or substitute a placeholder.","Mark such textures as non-serializable so the content pipeline excludes them."],"exampleFix":"// before\nserializer.Serialize(stream, renderTargetTexture);\n// after\nif (renderTargetTexture.GetSerializationData() == null)\n    throw new NotSupportedException(\"Texture has no CPU-side serialization data; load from an asset instead.\");\nserializer.Serialize(stream, renderTargetTexture);","handlingStrategy":"validation","validationCode":"if (texture.GetSerializationData() == null)\n    throw new NotSupportedException($\"Texture {texture.Name} has no CPU-side serialization data and cannot be saved.\");","typeGuard":"bool IsSerializableTexture(Texture t) => t.GetSerializationData() != null;","tryCatchPattern":"try\n{\n    serializer.Serialize(stream, texture);\n}\ncatch (InvalidOperationException ex)\n{\n    log.Warn(ex, \"Skipping non-serializable (GPU-only) texture\");\n    // exclude texture or save a placeholder\n}","preventionTips":["Only serialize asset-loaded textures, never render targets or GPU-allocated textures","Check GetSerializationData() before adding textures to serializable scenes","Read back GPU textures into a staging texture if a snapshot is truly needed","Mark dynamic textures as non-serializable in your asset model"],"tags":["textures","serialization","gpu","stride"],"backgroundTag":"internal-invariant-violation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}