{"record":{"id":"3a66e57a8046bd99","repo":"Tichau/FileConverter","slug":"the-conversion-preset-must-be-valid-3a66e5","errorCode":null,"errorMessage":"The conversion preset must be valid.","messagePattern":"The conversion preset must be valid\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs","lineNumber":432,"sourceCode":"            if (this.ffmpegArgumentStringByPass.Count == 0)\n            {\n                throw new Exception(\"No ffmpeg arguments generated.\");\n            }\n\n            for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++)\n            {\n                if (string.IsNullOrEmpty(this.ffmpegArgumentStringByPass[index].Arguments))\n                {\n                    throw new Exception(\"Invalid ffmpeg process arguments.\");\n                }\n            }\n        }\n        \n        protected override void Convert()\n        {\n            if (this.ConversionPreset == null)\n            {\n                throw new Exception(\"The conversion preset must be valid.\");\n            }\n\n            for (int index = 0; index < this.ffmpegArgumentStringByPass.Count; index++)\n            {\n                FFMpegPass currentPass = this.ffmpegArgumentStringByPass[index];\n\n                this.UserState = currentPass.Name;\n                this.ffmpegProcessStartInfo.Arguments = currentPass.Arguments;\n\n                Diagnostics.Debug.Log($\"Execute command: {this.ffmpegProcessStartInfo.FileName} {this.ffmpegProcessStartInfo.Arguments}.\");\n                Diagnostics.Debug.Log(string.Empty);\n\n                try\n                {\n                    using (Process exeProcess = Process.Start(this.ffmpegProcessStartInfo))\n                    {\n                        using (StreamReader reader = exeProcess.StandardError)\n                        {","sourceCodeStart":414,"sourceCodeEnd":450,"githubUrl":"https://github.com/Tichau/FileConverter/blob/6c157a411fb70fb7440d2e3b226042781fd55b15/Application/FileConverter/ConversionJobs/ConversionJob_FFMPEG.cs#L414-L450","documentation":"ConversionJob_FFMPEG.Convert() throws Exception when this.ConversionPreset is null before iterating the ffmpeg pass list (ffmpegArgumentStringByPass) and launching the ffmpeg process. As the generic fallback created by ConversionJobFactory.Create for any output type not handled by a specialized job, it relies on the preset to build its argument passes during Initialize(). The base ctor already null-guards the preset, so reaching this line means the parameterless design-mode constructor or a reflection/direct-call path bypassed the real constructor.","triggerScenarios":"ConversionJob_FFMPEG instantiated via its parameterless ctor then Convert() invoked; or Convert() called through reflection on an instance whose Initialize() never ran with a preset. Initialize() also separately throws 'Invalid ffmpeg process arguments.' when a pass has empty Arguments, but the preset guard precedes that loop.","commonSituations":"Design-time preview of an FFMPEG job; a test calling Convert() directly; a code path that constructed the generic fallback job before the preset was deserialized; misuse where the factory returned a job but the caller reset state.","solutions":["Always create the job with new ConversionJob_FFMPEG(conversionPreset, inputFilePath) (or via ConversionJobFactory.Create, which requires a non-null preset).","Call PrepareConversion() then StartConversion(); do not invoke Convert() directly.","For design-time, guard with if (ConversionPreset == null) return; at the top of Convert().","Ensure the preset is loaded and non-null before ConversionJobFactory.Create is called."],"exampleFix":"// before\nvar job = new ConversionJob_FFMPEG();\njob.Convert(); // throws: preset null\n\n// after\nvar job = ConversionJobFactory.Create(conversionPreset, inputFilePath);\njob.PrepareConversion(outputFilePath);\njob.StartConversion();","handlingStrategy":"validation","validationCode":"if (job == null || job.ConversionPreset == null)\n{\n    throw new InvalidOperationException(\n        \"ConversionJob_FFMPEG requires a non-null ConversionPreset; create it via ConversionJobFactory.Create.\");\n}\njob.StartConversion();","typeGuard":"private static bool HasValidPreset(ConversionJob job) => job != null && job.ConversionPreset != null;","tryCatchPattern":"try\n{\n    job.StartConversion();\n}\ncatch (Exception ex) when (ex.Message.Contains(\"conversion preset must be valid\"))\n{\n    logger.Error(ex, \"FFMPEG job created without a preset; rebuilding.\");\n    job = ConversionJobFactory.Create(LoadPreset(), inputPath);\n}","preventionTips":["Prefer ConversionJobFactory.Create(preset, inputPath) over newing a specific job type.","Never call Convert() directly; route through PrepareConversion() + StartConversion().","Validate the preset before passing it to the factory.","Keep the parameterless ctor for design-time only."],"tags":["csharp","fileconverter","conversion-preset","null-check","defensive-guard","ffmpeg","media"],"backgroundTag":null,"analyzedSha":"6c157a411fb70fb7440d2e3b226042781fd55b15","analyzedAt":"2026-08-13T15:04:08.307Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}