Unity-Technologies/UnityCsReference · error · Exception

Two consecutive assembly names found; last one: '{line}'

Error message

Two consecutive assembly names found; last one: '{line}'

What it means

Thrown when two per-assembly directives appear back-to-back. An '@assembly' line sets the PerAssemblyConfigFlag; encountering another '@assembly' line before any rule clears it is treated as an error because no rules were applied to the previous assembly.

Source

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

        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;
        }

        if (token[0] != ':')
        {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Add at least one rule line between consecutive '@assembly' directives, or remove the empty assembly header.
  2. Re-read the documented format: '@assembly' switches context, the next rules apply to that assembly.

Example fix

// before
@A.dll
@B.dll
:1 | Foo::Bar | error
// after
@A.dll
:1 | Foo::Bar | error
@B.dll
:2 | Baz::Qux | error
Defensive patterns

Strategy: validation

Validate before calling

// Reject two consecutive '@assembly' headers with no rule between them.
bool pendingAssembly = false;
foreach (var l in lines)
{
    var t = l.AsSpan().Trim();
    if (t.Length == 0 || t[0] == '#') continue;
    if (t.StartsWith("@"))
    {
        if (pendingAssembly) throw new FormatException($"No rules for previous assembly before: '{l}'");
        pendingAssembly = true;
    }
    else pendingAssembly = false;
}

Try / catch

try { config = RestrictedApisConfig.Load(path); }
catch (Exception ex) when (ex.Message.Contains("Two consecutive assembly names"))
{ /* add a rule under the first header or remove it */ }

Prevention

When it happens

Trigger: Two consecutive '@Assembly' lines in RestrictedApis.txt with no intervening ':id | signature | severity' rule between them.

Common situations: Listing multiple assemblies intending to share rules, or forgetting to add rules under the first assembly header.

Related errors


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