microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'config')
Error message
Value cannot be null. (Parameter 'config')
What it means
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.
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
Example fix
// before
var pool = new AksNodePoolResource("system", null!, aksEnv);
// after
var config = new AksNodePoolConfig { VmSize = "Standard_D4s_v5", NodeCount = 3 };
var pool = new AksNodePoolResource("system", config, aksEnv); Defensive patterns
Strategy: validation
Validate before calling
if (config is null)
{
throw new ArgumentNullException(nameof(config), "AKS node pool requires a non-null AksNodePoolConfig (vmSize, node count, autoscaling settings).");
}
var pool = new AksNodePoolResource(name, config, aksEnv); Type guard
if (config is not AksNodePoolConfig validConfig)
{
throw new ArgumentException("Expected a non-null AksNodePoolConfig.", nameof(config));
} Try / catch
try
{
var pool = new AksNodePoolResource(name, config, aksEnv);
}
catch (ArgumentNullException ex) when (ex.ParamName == "config")
{
// Fail with a clearer app-model error pointing at the resource name.
throw new InvalidOperationException($"Node pool '{name}' was created without an AksNodePoolConfig.", ex);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Object value cannot be null (ArgumentNullException: parent)
- Object value cannot be null (ArgumentNullException: parent)
- Value cannot be null. (Parameter 'parent')
- Value cannot be null. (Parameter 'parent')
- Value cannot be null. (Parameter 'parent')
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/371cec2edc80ad9b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Kubernetes/AksNodePoolResource.cs:29
/// that is used to generate Azure Bicep for the AKS agent pool profile.
/// </summary>
/// <param name="name">The name of the node pool resource.</param>
/// <param name="config">The Azure-specific node pool configuration.</param>
/// <param name="parent">The parent AKS environment resource.</param>
public class AksNodePoolResource(
string name,
AksNodePoolConfig config,
AzureKubernetesEnvironmentResource parent) : KubernetesNodePoolResource(name, parent.KubernetesEnvironment)
{
/// <summary>
/// Gets the parent AKS environment resource.
/// </summary>
public AzureKubernetesEnvironmentResource AksParent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));
/// <summary>
/// Gets the Azure-specific node pool configuration.
/// </summary>
public AksNodePoolConfig Config { get; } = config ?? throw new ArgumentNullException(nameof(config));
}
View on GitHub (pinned to 25830f84bd)