OrchardCMS/OrchardCore · error · AntivirusScanningException

The ClamAV antivirus scanner is enabled but the port…

Error message

The ClamAV antivirus scanner is enabled but the port setting is invalid.

What it means

Configuration guard in ClamAvFileEventHandler.ValidateOptions: the ClamAV feature is enabled but its Port setting is missing or not a valid number, so the client cannot be pointed at the scanner. Thrown during file upload processing (CreatingAsync) before any scan is attempted.

Solutions

  1. Set options.Port to clamd's listening port (default 3310).
  2. Check the config value binding — a non-numeric value binds to 0 and triggers this error.
  3. Cross-check clamd.conf TCPSocket port matches the configured value.
  4. Add a startup options validation to catch it before the first upload.

Example fix

// before
options.Port = 0; // unbound / unset
// after
options.Port = 3310;
Defensive patterns

Strategy: validation

Validate before calling

if (options.Port is < 1 or > 65535)
    throw new InvalidOperationException("ClamAV Port must be between 1 and 65535.");

Try / catch

try
{
    await UploadFileAsync(stream);
}
catch (AntivirusScanningException ex) when (ex.Message.Contains("port setting is invalid"))
{
    // correct the configuration before retrying uploads
}

Prevention

When it happens

Trigger: Antivirus feature enabled, file uploaded, and ClamAvOptions.Port is 0, negative, or above 65535 due to bad or defaulted configuration.

Common situations: Port typo (e.g. 33100 vs 3310), port left at default 0 while host was set, string config value that fails to bind and yields 0.

Understand the failure class

Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/283a6e70b5cf276a. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs:169

            {
                Message = new LocalizedString(nameof(ClamAvFileEventHandler), $"The uploaded file '{context.FileName}' was rejected because ClamAV detected '{signature}'."),
            });
        }

        throw new AntivirusScanningException(
            $"The ClamAV antivirus scanner returned an unexpected response while scanning '{context.FileName}': {response}");
    }

    private void ValidateOptions()
    {
        if (string.IsNullOrWhiteSpace(_options.Host))
        {
            throw new AntivirusScanningException("The ClamAV antivirus scanner is enabled but the host setting is missing.");
        }

        if (_options.Port is < 1 or > 65535)
        {
            throw new AntivirusScanningException("The ClamAV antivirus scanner is enabled but the port setting is invalid.");
        }

        if (_options.ConnectTimeoutSeconds <= 0)
        {
            throw new AntivirusScanningException("The ClamAV antivirus scanner is enabled but the connection timeout must be greater than zero.");
        }

        if (_options.TransferTimeoutSeconds <= 0)
        {
            throw new AntivirusScanningException("The ClamAV antivirus scanner is enabled but the transfer timeout must be greater than zero.");
        }
    }
}

View on GitHub (pinned to 4306c0717f)