Tichau/FileConverter · error · Exception

The conversion preset must be valid.

Error message

The conversion preset must be valid.

What it means

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.

Source

Thrown at Application/FileConverter/ConversionJobs/ConversionJob_Ico.cs:56

            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".png");

            // Convert input in png file to send it to ffmpeg for the ico conversion.
            ConversionPreset intermediatePreset = new ConversionPreset("To compatible image", OutputType.Png, this.ConversionPreset.InputTypes.ToArray());
            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageClampSizePowerOf2, "True");
            intermediatePreset.SetSettingsValue(ConversionPreset.ConversionSettingKeys.ImageMaximumSize, "256");
            this.pngConversionJob = ConversionJobFactory.Create(intermediatePreset, this.InputFilePath);
            this.pngConversionJob.PrepareConversion(this.intermediateFilePath);

            // Convert png file into ico.
            this.icoConversionJob = new ConversionJob_FFMPEG(this.ConversionPreset, this.intermediateFilePath);
            this.icoConversionJob.PrepareConversion(this.OutputFilePath);
        }

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

            Diagnostics.Debug.Log(string.Empty);
            Diagnostics.Debug.Log("Convert image to PNG (intermediate format).");
            this.pngConversionJob.StartConversion();

            if (this.pngConversionJob.State != ConversionState.Done)
            {
                this.ConversionFailed(this.pngConversionJob.ErrorMessage);
                return;
            }

            Diagnostics.Debug.Log(string.Empty);
            Diagnostics.Debug.Log("Convert png intermediate image to ICO.");
            this.icoConversionJob.StartConversion();

            if (this.icoConversionJob.State != ConversionState.Done)
            {

View on GitHub (pinned to 6c157a411f)

Solutions

  1. Use new ConversionJob_Ico(conversionPreset, inputFilePath) (ConversionJobFactory.Create routes ICO output here).
  2. Run PrepareConversion() then StartConversion(); avoid calling Convert() directly.
  3. In design-only contexts, return early when ConversionPreset is null.
  4. Validate the preset is loaded before job creation.

Example fix

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

// after
var job = ConversionJobFactory.Create(conversionPreset, inputFilePath);
job.PrepareConversion(outputFilePath);
job.StartConversion();
Defensive patterns

Strategy: validation

Validate before calling

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

Prevention

When it happens

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

Common situations: Design-time instantiation for XAML preview; tests calling Convert() directly; a pipeline that created the ICO job before the preset was deserialized.

Related errors


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