Unity-Technologies/UnityCsReference · error · Exception

Invalid configuration line: '{line}'

Error message

Invalid configuration line: '{line}'

What it means

Thrown while parsing a RestrictedApis.txt configuration line. After stripping comments, the first token had no '|' separator (NextToken returned separatorIndex -1) and did not start with '@', so the line is neither an assembly directive nor a valid rule. Every standalone (separator-less) line must be an '@assembly' directive.

Source

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

    {
        const byte PerAssemblyConfigFlag = 1;

        var lineSpan = line.AsSpan().Trim();
        if (lineSpan.Length == 0)
            return;

        var commentIndex = lineSpan.IndexOf('#');
        if (commentIndex != -1)
            lineSpan = lineSpan[..commentIndex].Trim();

        if (lineSpan.Length == 0)
            return;

        var token = NextToken(ref lineSpan, out var separatorIndex);
        if (separatorIndex == -1)
        {
            if (token[0] != '@')
                throw new Exception($"Invalid configuration line: '{line}'");

            if (flags.Get(PerAssemblyConfigFlag))
            {
                throw new Exception($"Two consecutive assembly names found; last one: '{line}'");
            }

            // Per-assembly configuration
            flags.Set(PerAssemblyConfigFlag, true);
            var assemblyPath = token.Slice(1).ToString();
            if (!_perAssemblyConfig.TryGetValue(assemblyPath, out var assemblySpecificConfigs))
            {
                assemblySpecificConfigs = new PerAssemblyConfig();
                _perAssemblyConfig.Add(assemblyPath, assemblySpecificConfigs);
            }

            currentMembersConfig = assemblySpecificConfigs._restrictedMembersConfig;
            currentTypesConfig = assemblySpecificConfigs._restrictedTypesConfig;
            return;

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Re-read the header comment in RestrictedApisConfig.cs: standalone lines must be '@Assembly.dll'; rules must be ':id | signature | severity [| description | doc url]'.
  2. Fix or delete the offending line shown in the message.
  3. Run the editor after editing to confirm the config parses.

Example fix

// before
MyRule
// after
@MyAssembly.dll
:1001 | System.IO.File::Open | error | Do not use File.Open | https://docs
Defensive patterns

Strategy: validation

Validate before calling

// A line with no '|' must be an '@assembly' directive.
var trimmed = line.AsSpan().Trim();
if (trimmed.Length > 0 && !trimmed.Contains('|') && !trimmed.StartsWith("@"))
    throw new FormatException($"Line is neither an @assembly directive nor a '|'-delimited rule: '{line}'");

Try / catch

try { config = RestrictedApisConfig.Load(path); }
catch (Exception ex) when (ex.Message.Contains("Invalid configuration line"))
{ /* fix the cited line, then reload */ }

Prevention

When it happens

Trigger: A line in RestrictedApis.txt with no '|' that is not an '@assembly' directive (e.g. a bare rule missing its '|' separators, or stray text).

Common situations: Hand-editing ProjectSettings/RestrictedApis.txt, malformed copy-paste of a rule, or a rule written without the required 'id | signature | severity' pipe separators.

Related errors


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