{"record":{"id":"371cec2edc80ad9b","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-config","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'config')","messagePattern":"Value cannot be null\\. \\(Parameter 'config'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.Kubernetes/AksNodePoolResource.cs","lineNumber":29,"sourceCode":"/// that is used to generate Azure Bicep for the AKS agent pool profile.\n/// </summary>\n/// <param name=\"name\">The name of the node pool resource.</param>\n/// <param name=\"config\">The Azure-specific node pool configuration.</param>\n/// <param name=\"parent\">The parent AKS environment resource.</param>\npublic class AksNodePoolResource(\n    string name,\n    AksNodePoolConfig config,\n    AzureKubernetesEnvironmentResource parent) : KubernetesNodePoolResource(name, parent.KubernetesEnvironment)\n{\n    /// <summary>\n    /// Gets the parent AKS environment resource.\n    /// </summary>\n    public AzureKubernetesEnvironmentResource AksParent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));\n\n    /// <summary>\n    /// Gets the Azure-specific node pool configuration.\n    /// </summary>\n    public AksNodePoolConfig Config { get; } = config ?? throw new ArgumentNullException(nameof(config));\n}\n","sourceCodeStart":11,"sourceCodeEnd":31,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.Kubernetes/AksNodePoolResource.cs#L11-L31","documentation":"AksNodePoolResource is a primary-constructor class whose Config property initializer throws ArgumentNullException when the 'config' parameter is null. The library treats the Azure-specific node pool configuration as mandatory because it is used to generate the AKS agent pool Bicep profile; constructing the resource without it is a programming error, so it fails fast at construction time.","triggerScenarios":"Calling the AksNodePoolResource constructor (directly or via a hosting API like AddAksNodePool) with a null AksNodePoolConfig argument, e.g. new AksNodePoolResource(\"pool\", null!, env) or passing an uninitialized config variable/return value of a factory that returned null.","commonSituations":"Passing the result of a config-builder method that can return null; misordered constructor arguments so null lands in the config slot; conditional config creation ('AksNodePoolConfig? cfg = condition ? Build() : null') then using cfg without a null check; C# nullable warnings suppressed with null! or #pragma.","solutions":["Construct a valid AksNodePoolConfig (e.g. with VM size and node count) and pass it instead of null","Check the argument order at the call site — null may be intended for a different parameter","If config comes from a factory/variable, null-check or use the null-forgiving-free pattern '?? throw new ArgumentNullException' before constructing","If you believe null config should be legal, file an issue; otherwise wrap construction in try/catch ArgumentNullException to surface a clearer message"],"exampleFix":"// before\nvar pool = new AksNodePoolResource(\"system\", null!, aksEnv);\n// after\nvar config = new AksNodePoolConfig { VmSize = \"Standard_D4s_v5\", NodeCount = 3 };\nvar pool = new AksNodePoolResource(\"system\", config, aksEnv);","handlingStrategy":"validation","validationCode":"if (config is null)\n{\n    throw new ArgumentNullException(nameof(config), \"AKS node pool requires a non-null AksNodePoolConfig (vmSize, node count, autoscaling settings).\");\n}\nvar pool = new AksNodePoolResource(name, config, aksEnv);","typeGuard":"if (config is not AksNodePoolConfig validConfig)\n{\n    throw new ArgumentException(\"Expected a non-null AksNodePoolConfig.\", nameof(config));\n}","tryCatchPattern":"try\n{\n    var pool = new AksNodePoolResource(name, config, aksEnv);\n}\ncatch (ArgumentNullException ex) when (ex.ParamName == \"config\")\n{\n    // Fail with a clearer app-model error pointing at the resource name.\n    throw new InvalidOperationException($\"Node pool '{name}' was created without an AksNodePoolConfig.\", ex);\n}","preventionTips":["Never pass null! to silence nullable warnings when constructing resources","Build the AksNodePoolConfig in the same expression as the resource so nullability is checked by the compiler","Null-check values returned from config factory methods before passing them on","Keep constructor argument order matched to the primary-constructor declaration"],"tags":["azure","aks","null-argument","constructor"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}