Unity-Technologies/UnityCsReference · error · Exception

Id ({intId}) overriden in configuration line '{line}' is not

Error message

Id ({intId}) overriden in configuration line '{line}' is not defined by any previous lines.

What it means

Thrown when a rule is an override (empty signature field, ':id | | severity') but the id was never introduced by a prior line. Overrides reuse a previously defined id's signature; an unknown id cannot be overridden.

Source

Thrown at Editor/Mono/Scripting/RestrictedApisValidation/RestrictedApisConfig.cs:185

        {
            description = NextToken(ref lineSpan,  out separatorIndex).ToString();
            if (separatorIndex != -1)
            {
                documentationUrl = NextToken(ref lineSpan,  out separatorIndex).ToString();
            }
        }

        if (!Int32.TryParse(id, out var intId))
        {
            throw new Exception($"Id must be a number (line: '{line}')");
        }

        int referenceHashCode;
        var isTypeSignature = false;
        if (signature.Length == 0)
        {
            if (!_idToSignatureDetails.TryGetValue(intId, out var previousMappedId))
                throw new Exception($"Id ({intId}) overriden in configuration line '{line}' is not defined by any previous lines.");

            (referenceHashCode, isTypeSignature)  = previousMappedId;
        }
        else
        {
            isTypeSignature = line.AsSpan().IndexOf("::") == -1; // member signatures must have a :: as a declaring type name/member name separator

            //TODO: When we switch from netstandard to *any* .NET BCL, remove the ToString() and call String.GetHashCode(signature) : https://learn.microsoft.com/en-us/dotnet/api/system.string.gethashcode?view=net-9.0#system-string-gethashcode(system-readonlyspan((system-char)))
            referenceHashCode = signature.ToString().GetHashCode();
            _idToSignatureDetails[intId] = new (referenceHashCode, isTypeSignature);
        }

        var targetContainer = isTypeSignature ?  currentTypesConfig :  currentMembersConfig;
        if (!Enum.TryParse<RestrictedApiSeverity>(severitySpan.ToString(), ignoreCase: true, out var severity))
        {
            throw new Exception($"Invalid severity '{severitySpan.ToString()}' in line '{line}'");
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Ensure the id was first defined with a signature in an earlier line before overriding it.
  2. Reorder the file so definitions precede overrides, or add the missing definition.

Example fix

// before
:1001 | | warning
// after
:1001 | System.IO.File::Open | error
:1001 | | warning
Defensive patterns

Strategy: validation

Validate before calling

// Overrides (empty signature) may only reference ids already defined.
HashSet<int> defined = new();
foreach (var l in lines)
{
    var parts = l.Split('|');
    if (parts.Length == 0 || !parts[0].TrimStart().StartsWith(":")) continue;
    if (!Int32.TryParse(parts[0].TrimStart()[1..], out var id)) continue;
    var sig = parts.Length > 1 ? parts[1].Trim() : "";
    if (sig.Length == 0 && !defined.Contains(id))
        throw new FormatException($"Override references undefined id {id}: '{l}'");
    if (sig.Length != 0) defined.Add(id);
}

Try / catch

try { config = RestrictedApisConfig.Load(path); }
catch (Exception ex) when (ex.Message.Contains("is not defined by any previous lines"))
{ /* move/restore the definition before the override */ }

Prevention

When it happens

Trigger: A line ':id | | severity' where 'id' was not defined earlier in the file by a full ':id | signature | severity' rule.

Common situations: Ordering override lines before their definition, deleting a definition while keeping its override, or mismatched ids.

Related errors


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