{"record":{"id":"1b5ba7768af1a968","repo":"Unity-Technologies/UnityCsReference","slug":"read-only-read-out-of-hashlengthspan-length-by","errorCode":null,"errorMessage":"Read only {read} out of {hashLengthSpan.Length} bytes for hash length.","messagePattern":"Read only (.+?) out of (.+?) bytes for hash length\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"critical","filePath":"Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs","lineNumber":309,"sourceCode":"                throw new InvalidDataException($\"\"\"\n                                                Invalid signature ({BitConverter.ToString(signatureHashSpan.ToArray())}) found (Expected: {BitConverter.ToString(Signature)}).{Environment.NewLine}\n                                                DependencyGraph file is either corrupted or from a previous version of Unity. If you observe inexplicable runtime/compilation errors, please delete `Library/` folder and reopen the project.\n                                                \"\"\");\n            }\n\n            int version = stream.ReadByte();\n            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;","sourceCodeStart":291,"sourceCodeEnd":327,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs#L291-L327","documentation":"Thrown by AssemblyDependencyGraph.LoadFrom as InvalidDataException when stream.Read returns fewer bytes than expected (sizeof(long) = 8) for the hash length field. This indicates the file is truncated or corrupted past the signature and version header. Unlike the signature/version errors, this is a structural read failure: the stream ended prematurely.","triggerScenarios":"The DependencyGraph file is truncated due to an interrupted write (Unity crashed during save). Disk full condition during file write. Manual truncation or partial copy of the file.","commonSituations":"Unity editor crash during domain reload leaving a half-written file. Antivirus or backup software locking/interfering with the file during write. Network drive sync conflicts.","solutions":["Delete the Library/ folder and reopen the project to regenerate the DependencyGraph.","Investigate disk health if truncation recurs frequently.","Ensure no external process locks Library/ files during Unity operation."],"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; truncation is an I/O failure.\n// Ensure the write process completes (no crashes during save).","typeGuard":null,"tryCatchPattern":"try\n{\n    AssemblyDependencyGraph.LoadFrom(stream);\n}\ncatch (InvalidDataException)\n{\n    // File is truncated; delete Library/ and regenerate.\n}","preventionTips":["Avoid force-killing Unity during domain reloads or saves.","Exclude Library/ from sync tools that may cause partial writes.","Monitor disk health if truncation recurs."],"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"}