{"record":{"id":"7ce368f07268e5b3","repo":"Tichau/FileConverter","slug":"the-conversion-preset-must-be-valid-7ce368","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_PowerPoint.cs","lineNumber":85,"sourceCode":"            }\n            else\n            {\n                // Generate intermediate file path.\n                string fileName = Path.GetFileNameWithoutExtension(this.InputFilePath);\n                string tempPath = Path.GetTempPath();\n                this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + \".pdf\");\n\n                ConversionPreset intermediatePreset = new ConversionPreset(\"Pdf to image\", this.ConversionPreset, \"pdf\");\n                this.pdf2ImageConversionJob = ConversionJobFactory.Create(intermediatePreset, this.intermediateFilePath);\n                this.pdf2ImageConversionJob.PrepareConversion(this.OutputFilePaths);\n            }\n        }\n\n        protected override void Convert()\n        {\n            if (this.ConversionPreset == null)\n            {\n                throw new System.Exception(\"The conversion preset must be valid.\");\n            }\n\n            this.UserState = Properties.Resources.ConversionStateReadDocument;\n\n            if (!this.TryLoadDocumentIfNecessary())\n            {\n                this.ConversionFailed(Properties.Resources.ErrorUnableToUseMicrosoftOffice);\n                return;\n            }\n\n            this.UserState = Properties.Resources.ConversionStateConversion;\n\n            Debug.Log(\"Convert PowerPoint document to pdf.\");\n            this.document.ExportAsFixedFormat(this.intermediateFilePath, PowerPoint.Enums.PpFixedFormatType.ppFixedFormatTypePDF);\n\n            Debug.Log($\"Close PowerPoint document '{this.InputFilePath}'.\");\n            this.document.Close();\n            this.document = null;","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/Tichau/FileConverter/blob/6c157a411fb70fb7440d2e3b226042781fd55b15/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs#L67-L103","documentation":"ConversionJob_PowerPoint.Convert() throws System.Exception when this.ConversionPreset is null before the NetOffice PowerPoint interop (load presentation, export intermediate PDF, then run the pdf2Image sub-job). The (preset, inputFilePath) base ctor already rejects null, so this guard is reachable only through the parameterless ConversionJob_PowerPoint() design-mode constructor or direct/reflection invocation of Convert(); Initialize() enforces the same invariant. The guard exists because a null preset would NRE when building the intermediate 'Pdf to image' ConversionPreset and the pdf2ImageConversionJob.","triggerScenarios":"A ConversionJob_PowerPoint created via its parameterless ctor has Convert() invoked; or reflection calls Convert() on an instance whose preset is null. StartConversion() would normally throw 'Invalid conversion state' first for the design-mode ctor (State=InProgress).","commonSituations":"XAML designer previewing the PowerPoint job; a unit test calling Convert() directly; an Office-interop pipeline that created the job before the preset was loaded.","solutions":["Construct via new ConversionJob_PowerPoint(conversionPreset, inputFilePath) (the factory routes .pptx/.ppt/.odp here).","Drive through PrepareConversion() + StartConversion(); never call Convert() directly.","Early-return in design-time when ConversionPreset is null.","Validate the preset is non-null after loading from settings."],"exampleFix":"// before\nvar job = new ConversionJob_PowerPoint();\njob.Convert(); // throws: preset null\n\n// after\nvar job = new ConversionJob_PowerPoint(conversionPreset, inputFilePath);\njob.PrepareConversion(outputFilePaths);\njob.StartConversion();","handlingStrategy":"validation","validationCode":"if (job == null || job.ConversionPreset == null)\n{\n    throw new InvalidOperationException(\n        \"ConversionJob_PowerPoint 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, \"PowerPoint job created without a preset.\");\n    job = new ConversionJob_PowerPoint(LoadPreset(), inputPath);\n}","preventionTips":["Construct PowerPoint jobs via the (preset, path) ctor or ConversionJobFactory.Create.","Drive execution through StartConversion(), not Convert().","Validate the preset is loaded before job creation.","Reserve the parameterless ctor for design time."],"tags":["csharp","fileconverter","conversion-preset","null-check","defensive-guard","powerpoint","office-interop"],"backgroundTag":null,"analyzedSha":"6c157a411fb70fb7440d2e3b226042781fd55b15","analyzedAt":"2026-08-13T15:04:08.307Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}