{"record":{"id":"515136c4348581a7","repo":"Unity-Technologies/UnityCsReference","slug":"read-only-read-out-of-storedhash-length-bytes","errorCode":null,"errorMessage":"Read only {read} out of {storedHash.Length} bytes for hash.","messagePattern":"Read only (.+?) out of (.+?) bytes for hash\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"critical","filePath":"Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs","lineNumber":316,"sourceCode":"            if (version != Version)\n            {\n                throw new InvalidDataException($\"\"\"\n                                                Unsupported DependencyGraph version ({version}).{Environment.NewLine}\n                                                DependencyGraph file is either corrupted or from a newer version of Unity.\n                                                \"\"\");\n            }\n\n            Span<byte> hashLengthSpan = stackalloc byte[sizeof(long)];\n            read = stream.Read(hashLengthSpan);\n            if (read != hashLengthSpan.Length)\n                throw new InvalidDataException($\"Read only {read} out of {hashLengthSpan.Length} bytes for hash length.\");\n\n            long hashLengthSize = BitConverter.ToInt64(hashLengthSpan);\n            Debug.Assert(hashLengthSize < 256);\n            Span<byte> storedHash = stackalloc byte[(int)hashLengthSize];\n            read = stream.Read(storedHash);\n            if (read != hashLengthSize)\n                throw new InvalidDataException($\"Read only {read} out of {storedHash.Length} bytes for hash.\");\n\n            var startOfSerializedData = stream.Position;\n            var hasher = SHA256.Create();\n            var computedHash = hasher.ComputeHash(stream);\n            if (storedHash.Length != computedHash.Length)\n            {\n                return null;\n            }\n\n            if (!computedHash.AsSpan().SequenceEqual(storedHash))\n                return null;\n\n            stream.Position = startOfSerializedData;\n\n            var serializer = new DataContractSerializer(\n                typeof(AssemblyDependencyGraph),\n                new DataContractSerializerSettings { PreserveObjectReferences = true });\n            return (AssemblyDependencyGraph)serializer.ReadObject(stream);","sourceCodeStart":298,"sourceCodeEnd":334,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs#L298-L334","documentation":"Thrown by AssemblyDependencyGraph.LoadFrom as InvalidDataException when stream.Read returns fewer bytes than hashLengthSize for the stored hash field. The hash length was read successfully, but the actual hash bytes following it are fewer than declared. This is a truncation in the hash portion of the file, indicating corruption or an incomplete write.","triggerScenarios":"File truncated after the hash length field but before the full hash payload. hashLengthSize value itself is corrupted (e.g., a very large number from garbage data) causing the read to come up short. Interrupted write during serialization.","commonSituations":"Unity crash during project save. Corrupted download or copy of a project's Library/ folder. Disk errors in the Library/ directory.","solutions":["Delete the Library/ folder and reopen the project to regenerate all cached data.","Run a disk check if file corruption is recurrent.","Exclude Library/ from sync/sharing tools that may cause partial writes."],"exampleFix":"// No code fix; environment issue.\n// Terminal fix:\n//   rm -rf Library/\n// Then reopen the project in Unity.","handlingStrategy":"fallback","validationCode":"// No preventive validation; corruption is detected at read time.\n// Ensure no external process interferes with Library/ files.","typeGuard":null,"tryCatchPattern":"try\n{\n    AssemblyDependencyGraph.LoadFrom(stream);\n}\ncatch (InvalidDataException)\n{\n    // Hash region corrupted; delete Library/ and regenerate.\n}","preventionTips":["Do not manually edit or partially copy Library/ files.","Ensure antivirus does not quarantine parts of the DependencyGraph file.","Delete Library/ and reopen if errors recur after a crash."],"tags":["unity","dependency-graph","editor","corruption","io"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}