microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'parent')
Error message
Value cannot be null. (Parameter 'parent')
What it means
The AzureKeyVaultSecretResource constructor validates its 'parent' argument and throws ArgumentNullException ('Value cannot be null. (Parameter \'parent\')') when a null AzureKeyVaultResource is passed. The Parent property initializer enforces that every secret resource is attached to a real vault resource.
Solutions
- Pass the actual AzureKeyVaultResource instance as the parent argument.
- Prefer the public AddSecret extension APIs instead of constructing AzureKeyVaultSecretResource yourself.
- In test code, create the vault resource first with builder.AddAzureKeyVault(...) and use it as the parent.
Example fix
// before
var secret = new AzureKeyVaultSecretResource("db-pass", "db-pass", value, null!);
// after
var vault = builder.AddAzureKeyVault("kv");
var secret = new AzureKeyVaultSecretResource("db-pass", "db-pass", value, vault.Resource); Defensive patterns
Strategy: validation
Validate before calling
if (parent is null)
{
throw new ArgumentNullException(nameof(parent), "A non-null AzureKeyVaultResource is required to construct a secret resource.");
} Try / catch
try { var secret = new AzureKeyVaultSecretResource(...); }
catch (ArgumentNullException ex) when (ex.ParamName == "parent") { /* construct the vault resource first */ } Prevention
- Create the vault resource before any secret resources.
- Prefer AddSecret extension APIs over direct construction.
- Enable nullable reference types so null parents are caught at compile time.
When it happens
Trigger: Constructing AzureKeyVaultSecretResource directly (new AzureKeyVaultSecretResource(...)) passing null for the parent parameter, or via reflection/deserialization paths that supply null.
Common situations: Unit tests instantiating the secret resource manually, custom tooling building the resource graph, or factory code with an unassigned vault variable.
Related errors
- Value cannot be null. (Parameter 'value')
- Object value cannot be null (ArgumentNullException: parent)
- Object value cannot be null (ArgumentNullException: parent)
- Value cannot be null. (Parameter 'config')
- Value cannot be null. (Parameter 'parent')
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/6bb37e93827f25d3.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretResource.cs:30
/// </summary>
/// <remarks>
/// Use <see cref="AzureProvisioningResourceExtensions.ConfigureInfrastructure{T}(ApplicationModel.IResourceBuilder{T}, Action{AzureResourceInfrastructure})"/> to configure specific <see cref="Azure.Provisioning"/> properties.
/// </remarks>
[DebuggerDisplay("Type = {GetType().Name,nq}, Name = {Name}, Secret = {SecretName}")]
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;
View on GitHub (pinned to 25830f84bd)