{"record":{"id":"f6d9fca64e415648","repo":"stride3d/stride","slug":"bundle-has-not-been-properly-written","errorCode":null,"errorMessage":"Bundle has not been properly written","messagePattern":"Bundle has not been properly written","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Storage/BundleOdbBackend.cs","lineNumber":398,"sourceCode":"\n        // Read header\n        var header = binaryReader.Read<Header>();\n\n        var result = new BundleDescription\n        {\n            Header = header\n        };\n\n        // Check magic header\n        if (header.MagicHeader != Header.MagicHeaderValid)\n        {\n            throw new InvalidOperationException(\"Invalid bundle header\");\n        }\n\n        // Ensure size has properly been set\n        if (header.Size != stream.Length)\n        {\n            throw new InvalidOperationException(\"Bundle has not been properly written\");\n        }\n\n        // Read dependencies\n        var dependencies = result.Dependencies;\n        binaryReader.Serialize(ref dependencies, ArchiveMode.Deserialize);\n\n        // Read incremental bundles\n        var incrementalBundles = result.IncrementalBundles;\n        binaryReader.Serialize(ref incrementalBundles, ArchiveMode.Deserialize);\n\n        // Read objects\n        var objects = result.Objects;\n        binaryReader.Serialize(ref objects, ArchiveMode.Deserialize);\n\n        // Read assets\n        var assets = result.Assets;\n        binaryReader.Serialize(ref assets, ArchiveMode.Deserialize);\n","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Storage/BundleOdbBackend.cs#L380-L416","documentation":"After the magic header check, ReadBundleDescription compares the header's recorded Size with the actual stream length; if they differ it throws InvalidOperationException 'Bundle has not been properly written'. The bundle file is truncated (partially written) or extra data was appended.","triggerScenarios":"Reading a bundle file whose header.Size != stream.Length — interrupted CreateBundle write, disk-full during packaging, crash mid-write, or a truncated download.","commonSituations":"Build machine killed during packaging; copying files while they were still being written; network transfer cut off; incremental bundle update failing midway.","solutions":["Regenerate the bundle with CreateBundle / the asset build pipeline to produce a complete file.","Delete partial bundles before re-running the build so stale truncated files are not reused.","Add a post-build size/hash check that compares header.Size or file hash before shipping."],"exampleFix":"// before\ncopyFile(tmpPath, finalPath); // copy may race with writer\n// after\nwaitForWriteComplete(tmpPath);\nverifyBundleSize(finalPath, expectedHeaderSize);\ncopyFile(tmpPath, finalPath);","handlingStrategy":"validation","validationCode":"var fileInfo = new FileInfo(bundleUrl);\nusing var stream = File.OpenRead(bundleUrl);\n// header.Size is at a fixed offset in the bundle header; compare against stream length before full read\nif (ReadHeaderSize(stream) != stream.Length)\n    throw new InvalidDataException($\"{bundleUrl} is truncated or has trailing data.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var bundle = ReadBundleHeader(bundleUrl, out var files);\n}\ncatch (InvalidOperationException ex) when (ex.Message == \"Bundle has not been properly written\")\n{\n    DeleteCorruptBundle(bundleUrl);\n    RegenerateBundle(bundleUrl); // rebuild from source assets\n}","preventionTips":["Never copy bundles while a build is still writing them.","Delete partial/incremental bundles before rebuilding.","Add a CI check comparing header.Size (or hash) of shipped bundles."],"tags":["bundles","corruption","truncated-file"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}