{"record":{"id":"55a380f0243099b7","repo":"OrchardCMS/OrchardCore","slug":"the-clamav-antivirus-scanner-is-enabled-but-the-host-setting","errorCode":null,"errorMessage":"The ClamAV antivirus scanner is enabled but the host setting is missing.","messagePattern":"The ClamAV antivirus scanner is enabled but the host setting is missing\\.","errorType":"exception","errorClass":"AntivirusScanningException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs","lineNumber":164,"sourceCode":"            signature = signature[..^\" FOUND\".Length];\n\n            stream.Position = 0;\n\n            return FileCreatingResult.Failed(stream, new ResultError\n            {\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}","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.Antivirus/ClamAV/ClamAvFileEventHandler.cs#L146-L182","documentation":"The antivirus module validates ClamAvOptions before every scan. Because the feature is enabled but options.Host is null/empty/whitespace, ValidateOptions throws this AntivirusScanningException on the first file upload rather than silently skipping scanning.","triggerScenarios":"Antivirus/ClamAV feature enabled, a file upload triggers CreatingAsync, and _options.Host is null or whitespace because it was never configured.","commonSituations":"Enabling the ClamAV feature without adding configuration, appsettings section name typo, config binding not mapped to ClamAvOptions, missing environment variable in deployment.","solutions":["Configure the ClamAV host, e.g. via configuration or services.AddClamAv(o => o.Host = \"clamd\").","Check appsettings.json/appsettings.{env}.json for the correct ClamAV section and key names.","Verify config binding (environment variable prefixes, Azure App Configuration) actually reaches the app.","Validate at startup (fail fast) so missing host is caught before users upload files."],"exampleFix":"// before\n// feature enabled, no host configured\n// after\nservices.AddClamAv(options => { options.Host = \"clamd\"; options.Port = 3310; });","handlingStrategy":"validation","validationCode":"// at startup\nvar opts = configuration.GetSection(\"OrchardCore_Antivirus_ClamAV\").Get<ClamAvOptions>();\nif (string.IsNullOrWhiteSpace(opts?.Host))\n    throw new InvalidOperationException(\"ClamAV is enabled but Host is not configured.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await UploadFileAsync(stream);\n}\ncatch (AntivirusScanningException ex) when (ex.Message.Contains(\"host setting is missing\"))\n{\n    // fail deployment/startup validation instead of letting uploads 500\n}","preventionTips":["Validate ClamAvOptions at startup with IOptions validation.","Keep one source of truth for the config section name across environments.","Use CI config smoke tests that boot the app with production settings."],"tags":["clamav","configuration","missing-setting"],"backgroundTag":"missing-required-config-field","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"}