SubtitleEdit/subtitleedit · error · FormatException
Invalid ASSA time code: {time}
Error message
Invalid ASSA time code: {time} What it means
Thrown by AdvancedSubStationAlpha.GetTimeCodeFromString when a Dialogue line's start/end time field does not contain the expected h:mm:ss.cc separators. The parser uses IndexOfAny(':', '.') three times to slice the span; if any of the three separators is missing (i1/i2/i3 < 0) the time is unparseable and a FormatException is raised. This fires twice per Dialogue line during file load.
Source
Thrown at src/libse/SubtitleFormats/AdvancedSubStationAlpha.cs:1980
subtitle.Renumber();
Errors = errors.ToString();
}
private static TimeCode GetTimeCodeFromString(string time)
{
// h:mm:ss.cc - parsed with span slices; this runs twice per Dialogue line when
// loading a file, and the previous Split(':', '.') allocated a string[] plus one
// substring per part for every call.
var span = time.AsSpan();
var i1 = span.IndexOfAny(':', '.');
var afterHours = i1 < 0 ? default : span.Slice(i1 + 1);
var i2 = afterHours.IndexOfAny(':', '.');
var afterMinutes = i2 < 0 ? default : afterHours.Slice(i2 + 1);
var i3 = afterMinutes.IndexOfAny(':', '.');
if (i1 < 0 || i2 < 0 || i3 < 0)
{
throw new FormatException($"Invalid ASSA time code: {time}");
}
var afterSeconds = afterMinutes.Slice(i3 + 1);
var i4 = afterSeconds.IndexOfAny(':', '.');
var lastPart = (i4 < 0 ? afterSeconds : afterSeconds.Slice(0, i4)).Trim();
var ms = 0;
if (lastPart.Length == 2) // correct ASSA time code
{
ms = int.Parse(lastPart) * 10;
}
else if (lastPart.Length == 3)
{
ms = int.Parse(lastPart); // 3 digits, e.g. 123 = 123 ms
}
else if (lastPart.Length > 3)
{
ms = int.Parse(lastPart.Slice(0, 2)) * 10;View on GitHub (pinned to 17a9f07487)
Solutions
- Open the .ass file in a text editor and verify every Dialogue line's start/end times match h:mm:ss.cc (e.g. 0:00:01.23).
- If the file is a different format, force the correct format in SubtitleEdit instead of relying on auto-detection.
- Fix the offending line(s) manually or re-export from the original source.
- If loading programmatically, pre-validate times with a regex before calling LoadSubtitle.
Example fix
// before Dialogue: 0,1:23,2:00,Default,,0,0,0,,Hi // after Dialogue: 0,0:01:23.00,0:02:00.00,Default,,0,0,0,,Hi
Defensive patterns
Strategy: validation
Validate before calling
// Validate an ASSA time string before passing it to a loader/serializer
static bool IsValidAssaTime(string time)
{
if (string.IsNullOrWhiteSpace(time)) return false;
// Expect h:mm:ss.cc — at least three ':' or '.' separators
var sepCount = 0;
foreach (var c in time)
{
if (c == ':' || c == '.') sepCount++;
}
return sepCount >= 3;
}
// usage before load
if (lines.Any(l => l.StartsWith("Dialogue:", StringComparison.Ordinal)
&& !IsValidAssaTime(l.Split(',')[1])))
{
// warn user / sanitize
} Try / catch
// Wrap LoadSubtitle to report the offending line
try
{
new AdvancedSubStationAlpha().LoadSubtitle(sub, lines, fileName);
}
catch (FormatException ex) when (ex.Message.StartsWith("Invalid ASSA time code"))
{
// log ex.Message, prompt user to fix the time field, do not swallow silently
logger.Error(ex, "ASSA time code parse failed");
throw;
} Prevention
- Pre-validate Dialogue time fields with a regex like ^\d+:\d\d:\d\d\.\d\d$ before loading.
- Avoid hand-editing time fields; use a subtitle editor that validates on save.
- Sanitize imported files through a normalization pass that enforces h:mm:ss.cc.
When it happens
Trigger: Loading an .ass/.ssa file whose Dialogue timing fields are malformed — e.g. '1:23' (missing seconds or centiseconds), '123' (no separators at all), empty string, or a value using a comma instead of a dot/colon. Also triggered if a non-ASSA file is misdetected as ASSA.
Common situations: Hand-edited subtitle files with typos in time fields, files generated by a buggy exporter that drops the centisecond part, locale-specific files using comma decimal separators, or files with trailing/leading whitespace in the time field.
Related errors
- Unknown time format '{timeFormat}'
- Unknown type of event #{i + 1}: '{type}'
- Element 'events' not found.
- Parse error in event #{i + 1} style: {ex.Message}
- Parse error in event #{i + 1}: {ex.Message}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/75acfdca2fbef2f0.
Report an issue: GitHub.