Tichau/FileConverter · error · Exception

The conversion preset must be valid.

Error message

The conversion preset must be valid.

What it means

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.

Source

Thrown at Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs:85

            }
            else
            {
                // Generate intermediate file path.
                string fileName = Path.GetFileNameWithoutExtension(this.InputFilePath);
                string tempPath = Path.GetTempPath();
                this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".pdf");

                ConversionPreset intermediatePreset = new ConversionPreset("Pdf to image", this.ConversionPreset, "pdf");
                this.pdf2ImageConversionJob = ConversionJobFactory.Create(intermediatePreset, this.intermediateFilePath);
                this.pdf2ImageConversionJob.PrepareConversion(this.OutputFilePaths);
            }
        }

        protected override void Convert()
        {
            if (this.ConversionPreset == null)
            {
                throw new System.Exception("The conversion preset must be valid.");
            }

            this.UserState = Properties.Resources.ConversionStateReadDocument;

            if (!this.TryLoadDocumentIfNecessary())
            {
                this.ConversionFailed(Properties.Resources.ErrorUnableToUseMicrosoftOffice);
                return;
            }

            this.UserState = Properties.Resources.ConversionStateConversion;

            Debug.Log("Convert PowerPoint document to pdf.");
            this.document.ExportAsFixedFormat(this.intermediateFilePath, PowerPoint.Enums.PpFixedFormatType.ppFixedFormatTypePDF);

            Debug.Log($"Close PowerPoint document '{this.InputFilePath}'.");
            this.document.Close();
            this.document = null;

View on GitHub (pinned to 6c157a411f)

Solutions

  1. Construct via new ConversionJob_PowerPoint(conversionPreset, inputFilePath) (the factory routes .pptx/.ppt/.odp here).
  2. Drive through PrepareConversion() + StartConversion(); never call Convert() directly.
  3. Early-return in design-time when ConversionPreset is null.
  4. Validate the preset is non-null after loading from settings.

Example fix

// before
var job = new ConversionJob_PowerPoint();
job.Convert(); // throws: preset null

// after
var job = new ConversionJob_PowerPoint(conversionPreset, inputFilePath);
job.PrepareConversion(outputFilePaths);
job.StartConversion();
Defensive patterns

Strategy: validation

Validate before calling

if (job == null || job.ConversionPreset == null)
{
    throw new InvalidOperationException(
        "ConversionJob_PowerPoint requires a non-null ConversionPreset; use the (preset, inputFilePath) constructor.");
}
job.StartConversion();

Type guard

private static bool HasValidPreset(ConversionJob job) => job != null && job.ConversionPreset != null;

Try / catch

try
{
    job.StartConversion();
}
catch (Exception ex) when (ex.Message.Contains("conversion preset must be valid"))
{
    logger.Error(ex, "PowerPoint job created without a preset.");
    job = new ConversionJob_PowerPoint(LoadPreset(), inputPath);
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of Tichau/FileConverter@6c157a411f (2026-08-13). Data as JSON: /api/errors/7ce368f07268e5b3. Report an issue: GitHub.