microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'value')

Error message

Value cannot be null. (Parameter 'value')

What it means

The AzureKeyVaultSecretResource constructor validates its 'value' argument and throws ArgumentNullException ('Value cannot be null. (Parameter \'value\')') when null is supplied. The Value property holds the secret's value provider (an IValueProvider/manifest expression) and must always be present.

Solutions

  1. Pass a non-null value provider (e.g. a ParameterResource or ReferenceExpression-based IValueProvider) as the value argument.
  2. Use the AddSecret extension APIs so value construction is handled for you.
  3. In tests, supply a simple non-null IValueProvider implementation or parameter resource.

Example fix

// before
var secret = new AzureKeyVaultSecretResource(name, secretName, null!, vault);

// after
var param = builder.AddParameter("db-password", secret: true);
var secret = new AzureKeyVaultSecretResource(name, secretName, param.Resource, vault);
Defensive patterns

Strategy: validation

Validate before calling

if (value is null)
{
    throw new ArgumentNullException(nameof(value), "A non-null value provider is required to construct a secret resource.");
}

Try / catch

try { var secret = new AzureKeyVaultSecretResource(...); }
catch (ArgumentNullException ex) when (ex.ParamName == "value") { /* build the value provider first */ }

Prevention

When it happens

Trigger: Constructing AzureKeyVaultSecretResource directly with null for the value parameter, or calling low-level/factory paths where the secret's value expression failed to build.

Common situations: Unit tests building the resource manually, helper code passing a null parameter resource result, or refactoring that changed the value provider to return null.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/8eeb26b3e763819e. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretResource.cs:35

public class AzureKeyVaultSecretResource(string name, string secretName, AzureKeyVaultResource parent, object value)
    : Resource(name), IResourceWithParent<AzureKeyVaultResource>, IAzureKeyVaultSecretReference
{
    private readonly IAzureKeyVaultSecretReference _secret = parent.GetSecret(secretName);

    /// <summary>
    /// Gets or sets the secret name.
    /// </summary>
    public string SecretName => _secret.SecretName;

    /// <summary>
    /// Gets the parent Azure Key Vault resource.
    /// </summary>
    public AzureKeyVaultResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));

    /// <summary>
    /// Gets the value provider for the secret.
    /// </summary>
    public object Value { get; } = value ?? throw new ArgumentNullException(nameof(value));

    /// <summary>
    /// Gets the Azure Key Vault resource that contains this secret.
    /// </summary>
    IAzureKeyVaultResource IAzureKeyVaultSecretReference.Resource => Parent;

    IResource? IAzureKeyVaultSecretReference.SecretOwner { get; set; }

    /// <summary>
    /// Gets the expression for the secret value in the manifest.
    /// </summary>
    string IManifestExpressionProvider.ValueExpression => _secret.ValueExpression;

    /// <summary>
    /// Gets the secret value asynchronously.
    /// </summary>
    /// <param name="cancellationToken">The cancellation token.</param>
    /// <returns>The secret value.</returns>

View on GitHub (pinned to 25830f84bd)