Unity-Technologies/UnityCsReference · error · Exception
Invalid severity '' in line '{line}'
Error message
Invalid severity '' in line '{line}' What it means
Thrown when a rule line has ':id | signature' but no third field. After consuming id and signature, NextToken returns separatorIndex -1, meaning the severity field is missing, so the parser reports an empty severity.
Source
Thrown at Editor/Mono/Scripting/RestrictedApisValidation/RestrictedApisConfig.cs:161
}
currentMembersConfig = assemblySpecificConfigs._restrictedMembersConfig;
currentTypesConfig = assemblySpecificConfigs._restrictedTypesConfig;
return;
}
if (token[0] != ':')
{
// Invalid line
throw new Exception($"Invalid configuration line: '{line}'");
}
flags.Set(PerAssemblyConfigFlag, false); // Reset per-assembly configuration flag
var id = token.Slice(1);
var signature = NextToken(ref lineSpan, out separatorIndex);
if (separatorIndex == -1)
throw new Exception($"Invalid severity '' in line '{line}'");
var severitySpan = NextToken(ref lineSpan, out separatorIndex);
var description = "";
var documentationUrl = "";
if (separatorIndex != -1)
{
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}')");
}
View on GitHub (pinned to 225b0fbdb5)
Solutions
- Add the severity field: ':id | signature | error' (or warning/info).
- Double-check the line has at least three '|'-delimited fields: id, signature, severity.
Example fix
// before :1001 | System.IO.File::Open // after :1001 | System.IO.File::Open | error
Defensive patterns
Strategy: validation
Validate before calling
// A rule line needs at least three '|'-delimited fields: :id | signature | severity.
var parts = line.Split('|');
if (parts.Length < 3 && line.AsSpan().Trim().StartsWith(":"))
throw new FormatException($"Rule missing severity field: '{line}'"); Try / catch
try { config = RestrictedApisConfig.Load(path); }
catch (Exception ex) when (ex.Message.Contains("Invalid severity ''"))
{ /* add the severity field after the signature */ } Prevention
- Remember the minimum rule shape: ':id | signature | severity'.
- Treat an empty severity as a missing field during authoring.
When it happens
Trigger: A line like ':id | signature' with no severity token after the second '|'.
Common situations: Truncating a rule line, or forgetting the severity field when writing a rule.
Related errors
- Invalid configuration line: '{line}'
- Two consecutive assembly names found; last one: '{line}'
- Id must be a number (line: '{line}')
- Id ({intId}) overriden in configuration line '{line}' is not
- Invalid severity '{severitySpan.ToString()}' in line '{line}
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/feeb7f12e4a17b1f.
Report an issue: GitHub.