SubtitleEdit/subtitleedit · error · FileNotFoundException

Custom format template not found: {xmlPath}

Error message

Custom format template not found: {xmlPath}

What it means

Thrown by CustomFormatTemplateLoader.Load when the supplied XML path does not exist (File.Exists false). It is a FileNotFoundException carrying the path as FileName. The template file is required for custom text-format rendering, so its absence is fatal before any deserialisation.

Source

Thrown at src/seconv/Core/CustomFormatTemplateLoader.cs:30

public static class CustomFormatTemplateLoader
{
    [XmlRoot("CustomFormatItem")]
    public sealed class XmlShape
    {
        public string Name { get; set; } = string.Empty;
        public string Extension { get; set; } = string.Empty;
        public string FormatHeader { get; set; } = string.Empty;
        public string FormatParagraph { get; set; } = string.Empty;
        public string FormatFooter { get; set; } = string.Empty;
        public string FormatTimeCode { get; set; } = string.Empty;
        public string? FormatNewLine { get; set; }
    }

    public static CustomFormatTemplate Load(string xmlPath)
    {
        if (!File.Exists(xmlPath))
        {
            throw new FileNotFoundException($"Custom format template not found: {xmlPath}", xmlPath);
        }

        try
        {
            using var fs = File.OpenRead(xmlPath);
            var serializer = new XmlSerializer(typeof(XmlShape));
            var shape = (XmlShape?)serializer.Deserialize(fs)
                ?? throw new InvalidDataException($"Custom format template is empty: {xmlPath}");

            return new CustomFormatTemplate
            {
                Name = shape.Name,
                Extension = shape.Extension,
                FormatHeader = shape.FormatHeader,
                FormatParagraph = shape.FormatParagraph,
                FormatFooter = shape.FormatFooter,
                FormatTimeCode = shape.FormatTimeCode,
                FormatNewLine = shape.FormatNewLine,

View on GitHub (pinned to 17a9f07487)

Solutions

  1. Check the path exists (File.Exists) and use an absolute path to remove working-directory ambiguity.
  2. If using a relative path, resolve it against AppContext.BaseDirectory or the config directory explicitly.
  3. Ensure the template file is included in the build output / deployment package.

Example fix

// before
var tpl = CustomFormatTemplateLoader.Load("templates/my.xml");

// after
var path = Path.Combine(AppContext.BaseDirectory, "templates", "my.xml");
if (!File.Exists(path)) throw new FileNotFoundException("Template missing", path);
var tpl = CustomFormatTemplateLoader.Load(path);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(xmlPath))
    return Error($"Custom format template not found: {xmlPath}");
// Resolve relative paths against an explicit base directory first:
xmlPath = Path.GetFullPath(Path.IsPathRooted(xmlPath) ? xmlPath : Path.Combine(AppContext.BaseDirectory, xmlPath));

Try / catch

try { tpl = CustomFormatTemplateLoader.Load(xmlPath); }
catch (FileNotFoundException ex) { Console.Error.WriteLine(ex.Message); return; }

Prevention

When it happens

Trigger: Calling CustomFormatTemplateLoader.Load(xmlPath) where xmlPath points to a non-existent file (line 28). Common with a CLI --custom-template path that is misspelled, relative to the wrong working directory, or not deployed.

Common situations: A relative path resolved against an unexpected working directory; a template file that was not packaged/deployed with the app; a typo in the path; a path from config that is stale.

Related errors


AI-assisted analysis of SubtitleEdit/subtitleedit@17a9f07487 (2026-08-13). Data as JSON: /api/errors/4611d67cbe112cf5. Report an issue: GitHub.