{"record":{"id":"b01a6057c194b6ff","repo":"stride3d/stride","slug":"invalid-hash-code","errorCode":null,"errorMessage":"Invalid hash code.","messagePattern":"Invalid hash code\\.","errorType":"exception","errorClass":"ContentStreamingException","httpStatus":null,"severity":"error","filePath":"sources/core/Stride.Core.Serialization/Streaming/ContentStorage.cs","lineNumber":81,"sourceCode":"    internal ContentStorage(ContentStreamingService service)\n    {\n        Service = service;\n    }\n\n    internal void Init(ref ContentStorageHeader header)\n    {\n        Url = header.DataUrl;\n        chunks = new ContentChunk[header.ChunksCount];\n        for (int i = 0; i < chunks.Length; i++)\n        {\n            var e = header.Chunks[i];\n            chunks[i] = new ContentChunk(this, e.Location, e.Size);\n        }\n        PackageTime = header.PackageTime;\n\n        // Validate hash code\n        if (GetHashCode() != header.HashCode)\n            throw new ContentStreamingException(\"Invalid hash code.\", this);\n    }\n\n    /// <summary>\n    /// Gets the chunk.\n    /// </summary>\n    /// <param name=\"index\">The index.</param>\n    /// <returns>Chunk</returns>\n    public ContentChunk GetChunk(int index)\n    {\n        var chunk = chunks[index];\n        chunk.RegisterUsage();\n        return chunk;\n    }\n\n    internal void ReleaseUnusedChunks()\n    {\n        if (Interlocked.Read(ref locks) != 0)\n            return;","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/core/Stride.Core.Serialization/Streaming/ContentStorage.cs#L63-L99","documentation":"ContentStorage.Init reads a .pkt bundle header and reconstructs chunk entries, then validates that the recomputed GetHashCode() matches the header's stored HashCode. A mismatch means the storage index file was corrupted, truncated, or hand-edited — content integrity cannot be trusted.","triggerScenarios":"Opening a corrupted or partially written .pkt storage file; editing/serializing the storage with a mismatched Stride version; a failed download/copy leaving a stale index.","commonSituations":"Crash during asset packaging leaving an inconsistent bundle; syncing content files across versions where the header layout or hash algorithm changed; disk corruption.","solutions":["Rebuild the bundle/storage by re-running the asset compiler/game studio packaging step.","Restore the corrupted .pkt file from a known-good build artifact.","Verify file integrity after download/copy (hash the whole file) before loading; if you serialize custom storage, keep header hash computation in sync with ContentStorage.GetHashCode."],"exampleFix":"// no code fix — data problem\n// before: load corrupt bundle\nvar storage = ContentStorage.Load(provider, url);\n// after: validate first\nif (!FileChecksumMatches(url, expectedHash))\n    throw new InvalidOperationException(\"Bundle corrupted; repackage assets\");\nvar storage = ContentStorage.Load(provider, url);","handlingStrategy":"try-catch","validationCode":"// pre-validate file size and (if available) a known whole-file hash before load\nif (!File.Exists(url) || new FileInfo(url).Length == 0)\n    throw new FileNotFoundException(\"Bundle missing or empty, repackage needed\", url);","typeGuard":null,"tryCatchPattern":"try { storage = ContentStorage.Load(provider, url); }\ncatch (ContentStreamingException ex) when (ex.Message == \"Invalid hash code.\") {\n    logger.Error($\"Bundle {url} corrupted; repackage or restore from a known-good build.\");\n}","preventionTips":["Checksum bundles after download/copy and before first load","Never hand-edit .pkt files; always repackage via the asset compiler","Handle crashes during packaging by cleaning partial artifacts"],"tags":["serialization","content","corruption","checksum"],"backgroundTag":"checksum-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}