SubtitleEdit/subtitleedit · warning · InvalidOperationException
BDN XML document could not be created.
Error message
BDN XML document could not be created.
What it means
Thrown by ExportHandlerBdnXml after loading a hardcoded, valid BDN XML string via XmlDocument.LoadXml. The check guards against doc or doc.DocumentElement being null, which cannot happen with this specific literal string unless LoadXml throws first (in which case this line is never reached). This is a defensive, effectively-unreachable assertion.
Source
Thrown at src/libuilogic/Export/ExportHandlerBdnXml.cs:177
{
_last = new Paragraph(string.Empty, 0, 0);
}
var doc = new XmlDocument();
doc.LoadXml("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + Environment.NewLine +
"<BDN Version=\"0.93\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"BD-03-006-0093b BDN File Format.xsd\">" + Environment.NewLine +
"<Description>" + Environment.NewLine +
"<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 }))
{View on GitHub (pinned to 17a9f07487)
Solutions
- Treat as an assertion failure: capture a full stack trace and the runtime version.
- Verify the codebase has not subclassed XmlDocument or tampered with doc after LoadXml.
- If reproducible, replace the literal-string LoadXml with a programmatic build to isolate the cause.
Defensive patterns
Strategy: validation
Validate before calling
// The check is defensive over a hardcoded literal; in practice just assert after load
var doc = new XmlDocument();
doc.LoadXml(bdnLiteral);
if (doc.DocumentElement == null)
throw new InvalidOperationException("BDN XML failed to load a root element (unexpected - capture runtime info)."); Try / catch
// Unreachable in practice; treat any occurrence as a bug to investigate
try
{
exportHandler.Export();
}
catch (InvalidOperationException ex) when (ex.Message == "BDN XML document could not be created.")
{
logger.Critical(ex, "Defensive BDN XML assertion fired - capture full environment details.");
throw;
} Prevention
- Treat this throw as an assertion: if it fires, investigate the runtime/build, not normal operation.
- Do not edit the BDN XML literal without re-confirming it loads with a root element.
- Add a unit test that loads the literal and asserts doc.DocumentElement != null to guard refactors.
When it happens
Trigger: Only reachable if XmlDocument.LoadXml somehow returned a doc with a null DocumentElement for well-formed XML - a scenario the .NET XML parser does not produce. LoadXml would throw XmlException on malformed input before reaching the null check.
Common situations: Not expected to occur in practice. If it does, it indicates a corrupted .NET runtime, a custom XmlDocument subclass, or post-LoadXml reflection that nulled DocumentElement.
Related errors
- BDN XML Events node not found.
- 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/71287eff7e8e3103.
Report an issue: GitHub.