Tichau/FileConverter · error · Exception

The conversion preset must be valid.

Error message

The conversion preset must be valid.

What it means

ConversionJob_Word.Convert() throws System.Exception when this.ConversionPreset is null before the NetOffice Word interop (activate document, export intermediate PDF, then run the pdf2Image sub-job). The base ctor rejects null presets, so this fires only via the parameterless ConversionJob_Word() design-mode constructor or direct/reflection invocation; Initialize() re-asserts the same invariant. A null preset would otherwise NRE when constructing the 'Pdf to image' intermediate ConversionPreset and the pdf2ImageConversionJob.

Source

Thrown at Application/FileConverter/ConversionJobs/ConversionJob_Word.cs:86

            }
            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;
            }

            // Make this document the active document.
            this.document.Activate();

            this.UserState = Properties.Resources.ConversionStateConversion;

            Debug.Log("Convert word document to pdf.");
            // this.document.ExportAsFixedFormat(this.intermediateFilePath, Word.WdExportFormat.wdExportFormatPDF);
            this.document.ExportAsFixedFormat(this.intermediateFilePath, 

View on GitHub (pinned to 6c157a411f)

Solutions

  1. Construct via new ConversionJob_Word(conversionPreset, inputFilePath) or ConversionJobFactory.Create.
  2. Use PrepareConversion() + StartConversion(); do not call Convert() directly.
  3. Early-return in design-time when ConversionPreset is null.
  4. Confirm preset loading succeeded before job creation.

Example fix

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

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

Strategy: validation

Validate before calling

if (job == null || job.ConversionPreset == null)
{
    throw new InvalidOperationException(
        "ConversionJob_Word 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, "Word job created without a preset.");
    job = new ConversionJob_Word(LoadPreset(), inputPath);
}

Prevention

When it happens

Trigger: A ConversionJob_Word created via its parameterless ctor has Convert() invoked; or reflection calls Convert() on an instance whose preset is null. The factory routes .docx/.doc/.odt inputs here and requires a non-null preset, so the normal path cannot reach the guard.

Common situations: XAML design-time instantiation; a unit test calling Convert() directly; a Word-conversion pipeline that created the job before the preset was deserialized from settings.

Related errors


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