{"record":{"id":"77c0551fd5bbfb22","repo":"Unity-Technologies/UnityCsReference","slug":"dependency-graph-data-seems-to-be-corrupted-expec","errorCode":null,"errorMessage":"Dependency graph data seems to be corrupted. Expected {lengthOfDataExcludingPayload} bytes but got {stream.Length} bytes.","messagePattern":"Dependency graph data seems to be corrupted\\. Expected (.+?) bytes but got (.+?) bytes\\.","errorType":"exception","errorClass":"InvalidDataException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs","lineNumber":346,"sourceCode":"\n            stream.Position = startOfSerializedData;\n\n            var serializer = new DataContractSerializer(\n                typeof(AssemblyDependencyGraph),\n                new DataContractSerializerSettings { PreserveObjectReferences = true });\n            return (AssemblyDependencyGraph)serializer.ReadObject(stream);\n        }\n\n        static void ValidateMinimumLength(Stream stream)\n        {\n            var lengthOfDataExcludingPayload =\n                                Signature.Length +\n                                1 + // Version\n                                sizeof(long) + // hash length\n                                32; // actual SHA256 hash\n            if (stream.Length < lengthOfDataExcludingPayload + 1)\n            {\n                throw new InvalidDataException($\"Dependency graph data seems to be corrupted. Expected {lengthOfDataExcludingPayload} bytes but got {stream.Length} bytes.\");\n            }\n        }\n\n        internal DependencyEntry FindAssembly(string dependent)\n        {\n            return m_Graph.Find(e => e.m_Name == dependent);\n        }\n\n        [Serializable]\n        [DataContract]\n        internal class DependencyEntry : IComparable<DependencyEntry>\n        {\n            [DataMember]\n            public string m_Name;\n            [DataMember]\n            public List<DependencyEntry> m_Dependencies;\n\n            public DependencyEntry()","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs#L328-L364","documentation":"Thrown by ValidateMinimumLength while deserializing the cached assembly dependency graph. The reader expects a fixed header (signature + 1 version byte + 8-byte hash length + 32-byte SHA256 hash) plus at least one payload byte; if the stream is shorter than that minimum, the cached binary is considered truncated or corrupted and reading is aborted before deserialization.","triggerScenarios":"Calling the dependency graph load path (AssemblyDependencyGraph deserialization) on a stream whose Length is below Signature.Length + 1 + sizeof(long) + 32 + 1 bytes, i.e. ValidateMinimumLength runs against a short/garbage stream.","commonSituations":"Corrupted or partially-written Library/ cache (editor killed mid-write, disk full, interrupted import), a Library/ folder copied from source control with partial files, or a dependency-graph cache produced by a different/incompatible Unity version.","solutions":["Delete the Library/ folder (or specifically the dependency graph cache file) and relaunch Unity to rebuild it.","Free disk space and ensure no process terminates the editor during a build/import.","If it persists on a clean Library/, verify the project was not migrated across incompatible Unity versions and re-import assets."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Minimum header size the reader requires: signature + version + hash length + 32-byte hash + 1 payload byte.\n// Replace Signature.Length with the actual signature constant used by the reader.\nlong min = Signature.Length + 1 + sizeof(long) + 32 + 1;\nif (stream == null || stream.Length < min)\n    throw new InvalidDataException($\"Dependency graph stream too short ({stream?.Length}); rebuild the cache.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var graph = AssemblyDependencyGraph.Load(stream);\n}\ncatch (InvalidDataException)\n{\n    // Cache is corrupt: delete and rebuild.\n    File.Delete(cacheFilePath);\n    var graph = AssemblyDependencyGraph.Rebuild();\n}","preventionTips":["Treat the Library/ dependency-graph cache as disposable; never partially commit it.","Ensure the editor is not killed mid-write; free disk space.","After a Unity upgrade, clear stale caches to avoid version mismatch."],"tags":["cache","serialization","build","dependency-graph"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}