SubtitleEdit/subtitleedit · warning · InvalidOperationException
BDN XML Events node not found.
Error message
BDN XML Events node not found.
What it means
Thrown by ExportHandlerBdnXml when SelectSingleNode("Events") on the freshly loaded BDN document returns null. Like error 57, this guards a state that the hardcoded XML literal (which contains an <Events> element) cannot produce. It would only fire if the loaded XML's structure changed unexpectedly.
Source
Thrown at src/libuilogic/Export/ExportHandlerBdnXml.cs:185
"<Name Title=\"subtitle_exp\" Content=\"\"/>" + Environment.NewLine +
"<Language Code=\"eng\"/>" + Environment.NewLine +
"<Format VideoFormat=\"" + videoFormat + "\" FrameRate=\"" + _frameRate.ToString(CultureInfo.InvariantCulture) + "\" DropFrame=\"false\"/>" + Environment.NewLine +
"<Events Type=\"Graphic\" FirstEventInTC=\"" + ToHHMMSSFF(_first.StartTime) + "\" LastEventOutTC=\"" + ToHHMMSSFF(_last.EndTime) + "\" NumberofEvents=\"" + _imagesSavedCount.ToString(CultureInfo.InvariantCulture) + "\"/>" + Environment.NewLine +
"</Description>" + Environment.NewLine +
"<Events>" + Environment.NewLine +
"</Events>" + Environment.NewLine +
"</BDN>");
if (doc == null || doc.DocumentElement == null)
{
throw new InvalidOperationException("BDN XML document could not be created.");
}
XmlNode? events = doc.DocumentElement.SelectSingleNode("Events");
doc.PreserveWhitespace = true;
if (events == null)
{
throw new InvalidOperationException("BDN XML Events node not found.");
}
events.InnerXml = _sb.ToString();
FileUtil.WriteAllTextWithDefaultUtf8(Path.Combine(_folderName, "index.xml"), FormatUtf8Xml(doc));
}
private static string FormatUtf8Xml(XmlDocument doc)
{
var sb = new StringBuilder();
using (var writer = XmlWriter.Create(sb, new XmlWriterSettings { Indent = true, Encoding = Encoding.UTF8 }))
{
doc.Save(writer);
}
return sb.ToString().Replace(" encoding=\"utf-16\"", " encoding=\"utf-8\"").Trim(); // "replace hack" due to missing encoding (encoding only works if it's the only parameter...)
}
private string ToHHMMSSFF(TimeCode timeCode)
{
var ms = timeCode.TotalMilliseconds;View on GitHub (pinned to 17a9f07487)
Solutions
- Confirm the BDN XML literal still contains the <Events> element.
- If namespaces are introduced, use an XmlNamespaceManager and a prefixed XPath in SelectSingleNode.
- Treat as an assertion: capture the actual doc.OuterXml for diagnosis.
Defensive patterns
Strategy: validation
Validate before calling
// Defensive check over a literal known to contain <Events>; guard the literal in a test
var doc = new XmlDocument();
doc.LoadXml(bdnLiteral);
Debug.Assert(doc.SelectSingleNode("//Events") != null, "BDN literal must contain an Events node"); Try / catch
try
{
exportHandler.Export();
}
catch (InvalidOperationException ex) when (ex.Message == "BDN XML Events node not found.")
{
logger.Critical(ex, "Defensive BDN Events-node assertion fired - capture doc.OuterXml.");
throw;
} Prevention
- Keep the <Events> element in the BDN literal; add a unit test asserting it is present after load.
- If introducing XML namespaces, switch SelectSingleNode to use an XmlNamespaceManager.
- Treat any real occurrence as a regression in the literal, not a runtime input problem.
When it happens
Trigger: After LoadXml of the literal that includes <Events></Events>, doc.DocumentElement.SelectSingleNode("Events") returns null. Practically unreachable unless the literal is edited to remove <Events> or a custom resolver/namespace handling interferes with SelectSingleNode.
Common situations: Not expected in production. Could appear during refactoring if someone removes the <Events> element from the literal or changes namespace handling such that the default-namespace query no longer matches.
Related errors
- BDN XML document could not be created.
- Failed to start llama-server
- Failed to start crispasr (cosyvoice3-tts)
- Failed to start crispasr (f5-tts)
- NameList: Unable to read name list file: {fileNameOrUrl}
AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13).
Data as JSON: /api/errors/983585927183a38a.
Report an issue: GitHub.