{"record":{"id":"ae730c5c682ea17a","repo":"dotnetcore/CAP","slug":"value-cannot-be-null-parameter-options-ae730c","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'options')","messagePattern":"Value cannot be null\\. \\(Parameter 'options'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.ConsulDiscoveryOptionsExtensions.cs","lineNumber":54,"sourceCode":"        }\n    }\n}\n\nnamespace Microsoft.Extensions.DependencyInjection\n{\n    public static class CapDiscoveryOptionsExtensions\n    {\n        /// <summary>\n        /// Default use kubernetes as service discovery.\n        /// </summary>\n        public static CapOptions UseConsulDiscovery(this CapOptions capOptions)\n        {\n            return capOptions.UseConsulDiscovery(_ => { });\n        }\n\n        public static CapOptions UseConsulDiscovery(this CapOptions capOptions, Action<ConsulDiscoveryOptions> options)\n        {\n            if (options == null) throw new ArgumentNullException(nameof(options));\n\n            capOptions.RegisterExtension(new ConsulDiscoveryOptionsExtension(options));\n\n            return capOptions;\n        }\n    }\n}","sourceCodeStart":36,"sourceCodeEnd":61,"githubUrl":"https://github.com/dotnetcore/CAP/blob/e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb/src/DotNetCore.CAP.Dashboard/NodeDiscovery/CAP.ConsulDiscoveryOptionsExtensions.cs#L36-L61","documentation":"The CapOptions.UseConsulDiscovery extension method throws ArgumentNullException when the options delegate is null. CAP registers a ConsulDiscoveryOptionsExtension wrapping this Action<ConsulDiscoveryOptions>, so a null delegate would break node discovery configuration later. Passing null instead of a lambda (even an empty one) always fails immediately.","triggerScenarios":"Calling capOptions.UseConsulDiscovery(null) instead of passing at least an empty lambda _ => { }.","commonSituations":"Building options dynamically where a configuration section is missing and the code passes a null Action instead of falling back to defaults.","solutions":["Pass an empty lambda: UseConsulDiscovery(_ => { }).","Guard the call: only invoke UseConsulDiscovery when a configured action exists.","Provide real Consul settings (server address, node id/name) inside the lambda."],"exampleFix":"// before\nAction<ConsulDiscoveryOptions> configure = GetFromConfig(); // may be null\ncapOptions.UseConsulDiscovery(configure);\n// after\ncapOptions.UseConsulDiscovery(configure ?? (_ => { }));","handlingStrategy":"validation","validationCode":"if (configure == null) configure = _ => { };\ncapOptions.UseConsulDiscovery(configure);","typeGuard":null,"tryCatchPattern":"try { capOptions.UseConsulDiscovery(configure); }\ncatch (ArgumentNullException) { capOptions.UseConsulDiscovery(_ => { }); }","preventionTips":["Never pass null Actions to CAP option extension methods","Coalesce config-derived delegates with _ => { }","Validate Consul settings (server address, node id) inside the lambda"],"tags":["null-argument","configuration","consul","dotnet"],"backgroundTag":"null-argument","analyzedSha":"e52b8508e54cdb7a9ce7f9fec03d9ea8ad2710fb","analyzedAt":"2026-09-14T14:46:34.677Z","contentChangedAt":"2026-09-14T14:46:34.677Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}