Unity-Technologies/UnityCsReference · error · InvalidDataException
Dependency graph data seems to be corrupted. Expected {lengt
Error message
Dependency graph data seems to be corrupted. Expected {lengthOfDataExcludingPayload} bytes but got {stream.Length} bytes. What it means
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.
Source
Thrown at Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs:346
stream.Position = startOfSerializedData;
var serializer = new DataContractSerializer(
typeof(AssemblyDependencyGraph),
new DataContractSerializerSettings { PreserveObjectReferences = true });
return (AssemblyDependencyGraph)serializer.ReadObject(stream);
}
static void ValidateMinimumLength(Stream stream)
{
var lengthOfDataExcludingPayload =
Signature.Length +
1 + // Version
sizeof(long) + // hash length
32; // actual SHA256 hash
if (stream.Length < lengthOfDataExcludingPayload + 1)
{
throw new InvalidDataException($"Dependency graph data seems to be corrupted. Expected {lengthOfDataExcludingPayload} bytes but got {stream.Length} bytes.");
}
}
internal DependencyEntry FindAssembly(string dependent)
{
return m_Graph.Find(e => e.m_Name == dependent);
}
[Serializable]
[DataContract]
internal class DependencyEntry : IComparable<DependencyEntry>
{
[DataMember]
public string m_Name;
[DataMember]
public List<DependencyEntry> m_Dependencies;
public DependencyEntry()View on GitHub (pinned to 225b0fbdb5)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Minimum header size the reader requires: signature + version + hash length + 32-byte hash + 1 payload byte.
// Replace Signature.Length with the actual signature constant used by the reader.
long min = Signature.Length + 1 + sizeof(long) + 32 + 1;
if (stream == null || stream.Length < min)
throw new InvalidDataException($"Dependency graph stream too short ({stream?.Length}); rebuild the cache."); Try / catch
try
{
var graph = AssemblyDependencyGraph.Load(stream);
}
catch (InvalidDataException)
{
// Cache is corrupt: delete and rebuild.
File.Delete(cacheFilePath);
var graph = AssemblyDependencyGraph.Rebuild();
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Parameter asset is null
- Cannot add dependency on invalid path.
- Cannot add source dependency on empty GUID.
- Cannot add dependency on invalid ArtifactKey.
- Cannot add artifact dependency on empty GUID.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/77c0551fd5bbfb22.
Report an issue: GitHub.