{"record":{"id":"6bb37e93827f25d3","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-parent-6bb37e","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'parent')","messagePattern":"Value cannot be null\\. \\(Parameter 'parent'\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretResource.cs","lineNumber":30,"sourceCode":"/// </summary>\n/// <remarks>\n/// Use <see cref=\"AzureProvisioningResourceExtensions.ConfigureInfrastructure{T}(ApplicationModel.IResourceBuilder{T}, Action{AzureResourceInfrastructure})\"/> to configure specific <see cref=\"Azure.Provisioning\"/> properties.\n/// </remarks>\n[DebuggerDisplay(\"Type = {GetType().Name,nq}, Name = {Name}, Secret = {SecretName}\")]\npublic class AzureKeyVaultSecretResource(string name, string secretName, AzureKeyVaultResource parent, object value)\n    : Resource(name), IResourceWithParent<AzureKeyVaultResource>, IAzureKeyVaultSecretReference\n{\n    private readonly IAzureKeyVaultSecretReference _secret = parent.GetSecret(secretName);\n\n    /// <summary>\n    /// Gets or sets the secret name.\n    /// </summary>\n    public string SecretName => _secret.SecretName;\n\n    /// <summary>\n    /// Gets the parent Azure Key Vault resource.\n    /// </summary>\n    public AzureKeyVaultResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));\n\n    /// <summary>\n    /// Gets the value provider for the secret.\n    /// </summary>\n    public object Value { get; } = value ?? throw new ArgumentNullException(nameof(value));\n\n    /// <summary>\n    /// Gets the Azure Key Vault resource that contains this secret.\n    /// </summary>\n    IAzureKeyVaultResource IAzureKeyVaultSecretReference.Resource => Parent;\n\n    IResource? IAzureKeyVaultSecretReference.SecretOwner { get; set; }\n\n    /// <summary>\n    /// Gets the expression for the secret value in the manifest.\n    /// </summary>\n    string IManifestExpressionProvider.ValueExpression => _secret.ValueExpression;\n","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.KeyVault/AzureKeyVaultSecretResource.cs#L12-L48","documentation":"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.","triggerScenarios":"Constructing AzureKeyVaultSecretResource directly (new AzureKeyVaultSecretResource(...)) passing null for the parent parameter, or via reflection/deserialization paths that supply null.","commonSituations":"Unit tests instantiating the secret resource manually, custom tooling building the resource graph, or factory code with an unassigned vault variable.","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."],"exampleFix":"// before\nvar secret = new AzureKeyVaultSecretResource(\"db-pass\", \"db-pass\", value, null!);\n\n// after\nvar vault = builder.AddAzureKeyVault(\"kv\");\nvar secret = new AzureKeyVaultSecretResource(\"db-pass\", \"db-pass\", value, vault.Resource);","handlingStrategy":"validation","validationCode":"if (parent is null)\n{\n    throw new ArgumentNullException(nameof(parent), \"A non-null AzureKeyVaultResource is required to construct a secret resource.\");\n}","typeGuard":null,"tryCatchPattern":"try { var secret = new AzureKeyVaultSecretResource(...); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"parent\") { /* construct the vault resource first */ }","preventionTips":["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."],"tags":["azure","key-vault","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"}