Unity-Technologies/UnityCsReference · error · Exception
Invalid severity '{severitySpan.ToString()}' in line '{line}
Error message
Invalid severity '{severitySpan.ToString()}' in line '{line}' What it means
Thrown when the severity field does not parse (case-insensitive) to the RestrictedApiSeverity enum. The severity token must be one of the valid enum names.
Source
Thrown at Editor/Mono/Scripting/RestrictedApisValidation/RestrictedApisConfig.cs:201
{
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}'");
}
targetContainer[referenceHashCode] = new RestrictedApiConfigEntry(intId, severity, description, documentationUrl);
static ReadOnlySpan<char> NextToken(ref ReadOnlySpan<char> data, out int separatorIndex)
{
separatorIndex = data.IndexOf('|');
if (separatorIndex == -1)
return data;
var toReturn = data.Slice(0, separatorIndex).Trim();
data = data.Slice(separatorIndex + 1);
return toReturn;
}
}
public RestrictedApiConfigEntry RestrictedApiSeverityFor(MemberReference memberReference)
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Use a valid RestrictedApiSeverity name (typically 'error', 'warning', 'info' — confirm against the enum).
- Correct the typo shown in the message.
Example fix
// before :1001 | System.IO.File::Open | critical // after :1001 | System.IO.File::Open | error
Defensive patterns
Strategy: validation
Validate before calling
// Severity must parse to the RestrictedApiSeverity enum.
if (!Enum.TryParse<RestrictedApiSeverity>(severitySpan.ToString(), ignoreCase: true, out _))
throw new FormatException($"Unknown severity '{severitySpan}' in: '{line}'"); Type guard
static bool IsValidSeverity(string s) =>
Enum.TryParse<RestrictedApiSeverity>(s, ignoreCase: true, out _); Try / catch
try { config = RestrictedApisConfig.Load(path); }
catch (Exception ex) when (ex.Message.Contains("Invalid severity"))
{ /* correct the severity token to a valid enum name */ } Prevention
- Restrict severities to the RestrictedApiSeverity enum names only.
- Cross-check severity spellings against the enum definition.
When it happens
Trigger: A rule line whose severity token is not a valid RestrictedApiSeverity value (e.g. 'critical', 'fatal', or a typo like 'eror').
Common situations: Typos, guessing a severity name that isn't an enum member, or using a value from a different validation system.
Related errors
- Invalid configuration line: '{line}'
- Two consecutive assembly names found; last one: '{line}'
- Invalid severity '' in line '{line}'
- Id must be a number (line: '{line}')
- Id ({intId}) overriden in configuration line '{line}' is not
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/97f5a1985687150c.
Report an issue: GitHub.