{"record":{"id":"f003312a95158a8c","repo":"Tichau/FileConverter","slug":"the-conversion-preset-must-be-valid-f00331","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_Gif.cs","lineNumber":70,"sourceCode":"                this.pngConversionJob.PrepareConversion(this.intermediateFilePath);\n\n                inputFilePath = this.intermediateFilePath;\n            }\n            else\n            {\n                inputFilePath = this.InputFilePath;\n            }\n\n            // Convert png file into ico.\n            this.gifConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, inputFilePath);\n            this.gifConversionJob.PrepareConversion(this.OutputFilePath);\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            Task updateProgress = this.UpdateProgress();\n\n            if (this.pngConversionJob != null)\n            {\n                this.UserState = Properties.Resources.ConversionStateReadIntputImage;\n\n                Diagnostics.Debug.Log(string.Empty);\n                Diagnostics.Debug.Log(\"Convert image to PNG (intermediate format).\");\n                this.pngConversionJob.StartConversion();\n\n                if (this.pngConversionJob.State != ConversionState.Done)\n                {\n                    this.ConversionFailed(this.pngConversionJob.ErrorMessage);\n                    return;\n                }\n            }","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/Tichau/FileConverter/blob/6c157a411fb70fb7440d2e3b226042781fd55b15/Application/FileConverter/ConversionJobs/ConversionJob_Gif.cs#L52-L88","documentation":"ConversionJob_Gif.Convert() throws Exception when this.ConversionPreset is null before delegating to its child jobs (an optional pngConversionJob to normalize the input image and a ConversionJob_FFMPEG that builds the GIF). The job constructs its FFMPEG child from this.ConversionPreset in Initialize(), so a null preset would propagate NREs into the child; the guard fails fast instead. Like the sibling jobs, the real ctor blocks null presets, so this fires only via the parameterless design-mode ctor or direct/reflection invocation of Convert().","triggerScenarios":"ConversionJob_Gif built via its parameterless ctor then Convert() invoked; or reflection calling Convert() on an instance whose preset is null. Initialize() already uses this.ConversionPreset to construct the FFMPEG child, so a null would also break initialization earlier.","commonSituations":"XAML design-time instantiation; unit tests exercising Convert() directly; a pipeline that created the GIF job before the image-output preset was loaded.","solutions":["Construct via new ConversionJob_Gif(conversionPreset, inputFilePath) or ConversionJobFactory.Create.","Drive the job through PrepareConversion() + StartConversion(), not Convert().","Early-return in design-time when ConversionPreset is null.","Confirm preset loading succeeded before creating the job."],"exampleFix":"// before\nvar job = new ConversionJob_Gif();\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_Gif requires a non-null ConversionPreset; use the (preset, inputFilePath) constructor.\");\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, \"GIF job created without a preset.\");\n    job = new ConversionJob_Gif(LoadPreset(), inputPath);\n}","preventionTips":["Construct GIF jobs via ConversionJobFactory.Create or the (preset, path) ctor.","Drive execution through StartConversion(), not Convert().","Load the image-output preset before creating the job.","Reserve the parameterless ctor for XAML design time."],"tags":["csharp","fileconverter","conversion-preset","null-check","defensive-guard","gif","image"],"backgroundTag":null,"analyzedSha":"6c157a411fb70fb7440d2e3b226042781fd55b15","analyzedAt":"2026-08-13T15:04:08.307Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}