Tichau/FileConverter · error · Exception

The conversion preset must be valid.

Error message

The conversion preset must be valid.

What it means

ConversionJob_ExtractCDA.Convert() throws Exception when this.ConversionPreset is null before it begins CD-audio ripping (open CDDrive, read the track, write intermediate WAV, then run the compression sub-job). The (preset, inputFilePath) base constructor already rejects null presets, so this guard is reachable in practice only through the parameterless ConversionJob_ExtractCDA() design-mode constructor that leaves ConversionPreset null, or via reflection/direct invocation of the protected Convert(). The ExtractCDA Initialize() at line 50 also re-checks, so the same invariant is enforced at both phases.

Source

Thrown at Application/FileConverter/ConversionJobs/ConversionJob_ExtractCDA.cs:121

                return;
            }

            // Generate intermediate file path.
            string fileName = Path.GetFileName(this.OutputFilePath);
            string tempPath = Path.GetTempPath();
            this.intermediateFilePath = PathHelpers.GenerateUniquePath(tempPath + fileName + ".wav");

            // Sub conversion job (for compression).
            this.compressionConversionJob = ConversionJobFactory.Create(this.ConversionPreset, this.intermediateFilePath);
            this.compressionConversionJob.PrepareConversion(this.OutputFilePath);
            this.compressionThread = Helpers.InstantiateThread("CDACompressionThread", this.CompressAsync);
        }

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

            Debug.Log("Starting CDA extraction.");

            this.UserState = Properties.Resources.ConversionStateExtraction;

            if (!this.diskDrive.IsCDReady())
            {
                this.ConversionFailed(Properties.Resources.ErrorCDDriveNotReady);
                return;
            }

            if (!this.diskDrive.Refresh())
            {
                Debug.Log("Can't refresh CD drive data.");
                this.ConversionFailed(Properties.Resources.ErrorCDDriveNotReady);
                return;
            }

View on GitHub (pinned to 6c157a411f)

Solutions

  1. Use new ConversionJob_ExtractCDA(conversionPreset, inputFilePath) so the base ctor validates the preset immediately.
  2. Route execution through PrepareConversion() + StartConversion() instead of calling Convert() directly.
  3. In design-time only contexts, early-return when ConversionPreset is null.
  4. Verify the preset object is non-null after loading from user settings before passing it to the factory.

Example fix

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

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

Strategy: validation

Validate before calling

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

Prevention

When it happens

Trigger: A ConversionJob_ExtractCDA created via its parameterless ctor has Convert() called; or reflection invokes Convert() on an instance whose preset was never set. Because the ripping path allocates a CDDrive and a compression ConversionJob from this.ConversionPreset, a null preset would NRE further down, so the guard fails fast.

Common situations: Design-time instantiation of the CDA job; a test harness exercising Convert() directly; conversion pipeline code that created the job before confirming the .cda input resolved to a loaded preset.

Related errors


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