Unity-Technologies/UnityCsReference · critical · InvalidDataException

Invalid signature ({BitConverter.ToString(signatureHashSpan.

Error message

Invalid signature ({BitConverter.ToString(signatureHashSpan.ToArray())}) found (Expected: {BitConverter.ToString(Signature)}).
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.

What it means

Thrown by AssemblyDependencyGraph.LoadFrom as InvalidDataException when the file's signature bytes do not match the expected Signature constant. The DependencyGraph binary file starts with a magic signature to identify its format; a mismatch indicates the file is corrupted, truncated, or was written by a different (incompatible) Unity version. The error message includes both the found and expected signatures and advises deleting the Library/ folder.

Source

Thrown at Editor/Mono/Scripting/APIUpdater/AssemblyDependencyGraph.cs:291

            stream.Position = payloadOffset; // Position the stream in the first byte of the serialized data (i.e, skip *hash length* and *hash*
            var hash = hasher.ComputeHash(stream);
            stream.Position = hashOffset; // position the stream past the *hash length* (i.e, *hash-first byte*)
            stream.Write(hash);

            stream.Position = endOfStream;
        }

        public static AssemblyDependencyGraph LoadFrom(Stream stream)
        {
            ValidateMinimumLength(stream);

            Span<byte> signatureHashSpan = stackalloc byte[Signature.Length];
            var read = stream.Read(signatureHashSpan);
            Debug.Assert(read == signatureHashSpan.Length); // ValidateMinimumLength() guarantees there's enough data to fulfill the request.

            if (!signatureHashSpan.SequenceEqual(Signature))
            {
                throw new InvalidDataException($"""
                                                Invalid signature ({BitConverter.ToString(signatureHashSpan.ToArray())}) found (Expected: {BitConverter.ToString(Signature)}).{Environment.NewLine}
                                                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.
                                                """);
            }

            int version = stream.ReadByte();
            if (version != Version)
            {
                throw new InvalidDataException($"""
                                                Unsupported DependencyGraph version ({version}).{Environment.NewLine}
                                                DependencyGraph file is either corrupted or from a newer version of Unity.
                                                """);
            }

            Span<byte> hashLengthSpan = stackalloc byte[sizeof(long)];
            read = stream.Read(hashLengthSpan);
            if (read != hashLengthSpan.Length)
                throw new InvalidDataException($"Read only {read} out of {hashLengthSpan.Length} bytes for hash length.");

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Delete the Library/ folder and reopen the project in Unity to force regeneration.
  2. Ensure all team members and CI use the same Unity version.
  3. Add Library/ to .gitignore to avoid stale files from version control.

Example fix

// No code fix; this is an environment issue.
// Terminal fix:
//   rm -rf Library/
// Then reopen the project in Unity.
Defensive patterns

Strategy: fallback

Validate before calling

// No runtime validation possible; the file is already written incorrectly.
// Prevent by excluding Library/ from version control and using consistent Unity versions.

Try / catch

try
{
    AssemblyDependencyGraph.LoadFrom(stream);
}
catch (InvalidDataException)
{
    // Delete Library/ and regenerate.
}

Prevention

When it happens

Trigger: Opening a project whose Library/ folder contains a DependencyGraph file from an older or newer Unity version. Manually editing or partially overwriting the file. Disk corruption affecting the Library/ folder.

Common situations: Switching Unity versions on the same project without clearing Library/. Pulling a project from version control that accidentally included Library/. Interrupted Unity process leaving a half-written file.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/f5a1ee4d486979b1. Report an issue: GitHub.