{"record":{"id":"283a6e70b5cf276a","repo":"OrchardCMS/OrchardCore","slug":"the-clamav-antivirus-scanner-is-enabled-but-the-port-setting","errorCode":null,"errorMessage":"The ClamAV antivirus scanner is enabled but the port setting is invalid.","messagePattern":"The ClamAV antivirus scanner is enabled but the port setting is invalid\\.","errorType":"exception","errorClass":"AntivirusScanningException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs","lineNumber":169,"sourceCode":"            {\n                Message = new LocalizedString(nameof(ClamAvFileEventHandler), $\"The uploaded file '{context.FileName}' was rejected because ClamAV detected '{signature}'.\"),\n            });\n        }\n\n        throw new AntivirusScanningException(\n            $\"The ClamAV antivirus scanner returned an unexpected response while scanning '{context.FileName}': {response}\");\n    }\n\n    private void ValidateOptions()\n    {\n        if (string.IsNullOrWhiteSpace(_options.Host))\n        {\n            throw new AntivirusScanningException(\"The ClamAV antivirus scanner is enabled but the host setting is missing.\");\n        }\n\n        if (_options.Port is < 1 or > 65535)\n        {\n            throw new AntivirusScanningException(\"The ClamAV antivirus scanner is enabled but the port setting is invalid.\");\n        }\n\n        if (_options.ConnectTimeoutSeconds <= 0)\n        {\n            throw new AntivirusScanningException(\"The ClamAV antivirus scanner is enabled but the connection timeout must be greater than zero.\");\n        }\n\n        if (_options.TransferTimeoutSeconds <= 0)\n        {\n            throw new AntivirusScanningException(\"The ClamAV antivirus scanner is enabled but the transfer timeout must be greater than zero.\");\n        }\n    }\n}\n","sourceCodeStart":151,"sourceCodeEnd":183,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs#L151-L183","documentation":"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.","triggerScenarios":"Antivirus feature enabled, file uploaded, and ClamAvOptions.Port is 0, negative, or above 65535 due to bad or defaulted configuration.","commonSituations":"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.","solutions":["Set options.Port to clamd's listening port (default 3310).","Check the config value binding — a non-numeric value binds to 0 and triggers this error.","Cross-check clamd.conf TCPSocket port matches the configured value.","Add a startup options validation to catch it before the first upload."],"exampleFix":"// before\noptions.Port = 0; // unbound / unset\n// after\noptions.Port = 3310;","handlingStrategy":"validation","validationCode":"if (options.Port is < 1 or > 65535)\n    throw new InvalidOperationException(\"ClamAV Port must be between 1 and 65535.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await UploadFileAsync(stream);\n}\ncatch (AntivirusScanningException ex) when (ex.Message.Contains(\"port setting is invalid\"))\n{\n    // correct the configuration before retrying uploads\n}","preventionTips":["Validate options at startup (ValidateOnStart with IValidateOptions).","Match Port to clamd.conf TCPSocket value.","Ensure numeric config values bind correctly (no stray strings)."],"tags":["clamav","configuration","port","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}