microsoft/aspire · error · ArgumentNullException
subnet
Error message
subnet
What it means
AdminDeploymentScriptSubnetAnnotation throws ArgumentNullException when the provided AzureSubnetResource is null. The annotation records the ACI subnet used for Azure SQL admin deployment scripts and requires a valid subnet resource.
Solutions
- Create the subnet with AddAzureSubnet (or equivalent) and pass its resource into the annotation.
- Ensure the subnet-creating builder call executed and returned a non-null resource before constructing the annotation.
- Use the built-in WithAdminDeploymentScriptStorage flow rather than attaching the annotation manually.
Example fix
// before
var annotation = new AdminDeploymentScriptSubnetAnnotation(GetSubnetMaybeNull("aci"));
// after
var subnet = builder.AddAzureSubnet("aci-subnet", vnet, "aci");
var annotation = new AdminDeploymentScriptSubnetAnnotation(subnet.Resource); Defensive patterns
Strategy: validation
Validate before calling
if (subnetResource is null) throw new InvalidOperationException("Subnet must be created before attaching the deployment script annotation."); Type guard
if (subnetResource is not null) { new AdminDeploymentScriptSubnetAnnotation(subnetResource); } Prevention
- Create the subnet resource before referencing it in annotations.
- Rely on built-in WithAdminDeploymentScript* extensions.
- Null-check conditional subnet creation results.
When it happens
Trigger: Constructing AdminDeploymentScriptSubnetAnnotation with a null subnet, e.g. when a lookup for the subnet resource failed or the WithAdminDeploymentScript call chain passed an unresolved resource.
Common situations: Custom infrastructure code attaching the annotation manually where the subnet was created conditionally and the variable is null; broken builder chains that did not create the subnet.
Related errors
- parent
- ArgumentNullException for parameter 'callback' (callback is…
- ArgumentNullException for parameter 'resource' (resource is…
- ArgumentNullException for parameter 'services' (services is…
- ArgumentNullException: hostBuilder
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/f1b15434975e81da.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.Sql/AdminDeploymentScriptSubnetAnnotation.cs:19
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure;
namespace Aspire.Hosting;
/// <summary>
/// Annotation that stores the ACI subnet reference for deployment script configuration.
/// </summary>
[Experimental("ASPIREAZURE003")]
internal sealed class AdminDeploymentScriptSubnetAnnotation(AzureSubnetResource subnet) : IResourceAnnotation
{
/// <summary>
/// Gets the ACI subnet resource used for deployment scripts.
/// </summary>
public AzureSubnetResource Subnet { get; } = subnet ?? throw new ArgumentNullException(nameof(subnet));
}
View on GitHub (pinned to 25830f84bd)