{"record":{"id":"765a57f84950fdc9","repo":"Tichau/FileConverter","slug":"the-conversion-preset-must-be-valid-765a57","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_Ico.cs","lineNumber":56,"sourceCode":"            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + \".png\");\n\n            // Convert input in png file to send it to ffmpeg for the ico conversion.\n            ConversionPreset intermediatePreset = new ConversionPreset(\"To compatible image\", OutputType.Png, this.ConversionPreset.InputTypes.ToArray());\n            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, \"True\");\n            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, \"256\");\n            this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath);\n            this.pngConversionJob.PrepareConversion(this.intermediateFilePath);\n\n            // Convert png file into ico.\n            this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, this.intermediateFilePath);\n            this.icoConversionJob.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            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\n            Diagnostics.Debug.Log(string.Empty);\n            Diagnostics.Debug.Log(\"Convert png intermediate image to ICO.\");\n            this.icoConversionJob.StartConversion();\n\n            if (this.icoConversionJob.State != ConversionState.Done)\n            {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Tichau/FileConverter/blob/6c157a411fb70fb7440d2e3b226042781fd55b15/Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs#L38-L74","documentation":"ConversionJob_Ico.Convert() throws Exception when this.ConversionPreset is null before running its two-stage pipeline (a pngConversionJob to produce an intermediate PNG, then a ConversionJob_FFMPEG to pack it into .ico). Initialize() builds both children from this.ConversionPreset, so the guard prevents a null from cascading into the FFMPEG child ctor. The base ctor blocks null presets, so this is reachable only via the parameterless design-mode constructor or direct/reflection invocation.","triggerScenarios":"ConversionJob_Ico instantiated through its parameterless ctor then Convert() called; or Convert() invoked via reflection on an instance whose preset is null. Initialize() at the same invariant also references this.ConversionPreset when building the children.","commonSituations":"Design-time instantiation for XAML preview; tests calling Convert() directly; a pipeline that created the ICO job before the preset was deserialized.","solutions":["Use new ConversionJob_Ico(conversionPreset, inputFilePath) (ConversionJobFactory.Create routes ICO output here).","Run PrepareConversion() then StartConversion(); avoid calling Convert() directly.","In design-only contexts, return early when ConversionPreset is null.","Validate the preset is loaded before job creation."],"exampleFix":"// before\nvar job = new ConversionJob_Ico();\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_Ico 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, \"ICO job created without a preset.\");\n    job = new ConversionJob_Ico(LoadPreset(), inputPath);\n}","preventionTips":["Create ICO jobs through ConversionJobFactory.Create (it routes OutputType.Ico here) or the (preset, path) ctor.","Use StartConversion(); avoid Convert().","Validate the preset before job creation.","Keep the parameterless ctor design-time only."],"tags":["csharp","fileconverter","conversion-preset","null-check","defensive-guard","ico","image"],"backgroundTag":null,"analyzedSha":"6c157a411fb70fb7440d2e3b226042781fd55b15","analyzedAt":"2026-08-13T15:04:08.307Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}