{"record":{"id":"4611d67cbe112cf5","repo":"SubtitleEdit/subtitleedit","slug":"custom-format-template-not-found-xmlpath","errorCode":null,"errorMessage":"Custom format template not found: {xmlPath}","messagePattern":"Custom format template not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/seconv/Core/CustomFormatTemplateLoader.cs","lineNumber":30,"sourceCode":"public static class CustomFormatTemplateLoader\n{\n    [XmlRoot(\"CustomFormatItem\")]\n    public sealed class XmlShape\n    {\n        public string Name { get; set; } = string.Empty;\n        public string Extension { get; set; } = string.Empty;\n        public string FormatHeader { get; set; } = string.Empty;\n        public string FormatParagraph { get; set; } = string.Empty;\n        public string FormatFooter { get; set; } = string.Empty;\n        public string FormatTimeCode { get; set; } = string.Empty;\n        public string? FormatNewLine { get; set; }\n    }\n\n    public static CustomFormatTemplate Load(string xmlPath)\n    {\n        if (!File.Exists(xmlPath))\n        {\n            throw new FileNotFoundException($\"Custom format template not found: {xmlPath}\", xmlPath);\n        }\n\n        try\n        {\n            using var fs = File.OpenRead(xmlPath);\n            var serializer = new XmlSerializer(typeof(XmlShape));\n            var shape = (XmlShape?)serializer.Deserialize(fs)\n                ?? throw new InvalidDataException($\"Custom format template is empty: {xmlPath}\");\n\n            return new CustomFormatTemplate\n            {\n                Name = shape.Name,\n                Extension = shape.Extension,\n                FormatHeader = shape.FormatHeader,\n                FormatParagraph = shape.FormatParagraph,\n                FormatFooter = shape.FormatFooter,\n                FormatTimeCode = shape.FormatTimeCode,\n                FormatNewLine = shape.FormatNewLine,","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/SubtitleEdit/subtitleedit/blob/17a9f0748781032255db3526b7215d2fb891e3af/src/seconv/Core/CustomFormatTemplateLoader.cs#L12-L48","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check the path exists (File.Exists) and use an absolute path to remove working-directory ambiguity.","If using a relative path, resolve it against AppContext.BaseDirectory or the config directory explicitly.","Ensure the template file is included in the build output / deployment package."],"exampleFix":"// before\nvar tpl = CustomFormatTemplateLoader.Load(\"templates/my.xml\");\n\n// after\nvar path = Path.Combine(AppContext.BaseDirectory, \"templates\", \"my.xml\");\nif (!File.Exists(path)) throw new FileNotFoundException(\"Template missing\", path);\nvar tpl = CustomFormatTemplateLoader.Load(path);","handlingStrategy":"validation","validationCode":"if (!File.Exists(xmlPath))\n    return Error($\"Custom format template not found: {xmlPath}\");\n// Resolve relative paths against an explicit base directory first:\nxmlPath = Path.GetFullPath(Path.IsPathRooted(xmlPath) ? xmlPath : Path.Combine(AppContext.BaseDirectory, xmlPath));","typeGuard":null,"tryCatchPattern":"try { tpl = CustomFormatTemplateLoader.Load(xmlPath); }\ncatch (FileNotFoundException ex) { Console.Error.WriteLine(ex.Message); return; }","preventionTips":["Pre-check File.Exists before calling Load, using an absolute path.","Resolve relative template paths against AppContext.BaseDirectory or the config directory explicitly.","Include template files in the build output / deployment package."],"tags":["custom-format","xml","file-not-found","template"],"backgroundTag":null,"analyzedSha":"17a9f0748781032255db3526b7215d2fb891e3af","analyzedAt":"2026-08-13T18:11:43.374Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}