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

  1. Create the subnet with AddAzureSubnet (or equivalent) and pass its resource into the annotation.
  2. Ensure the subnet-creating builder call executed and returned a non-null resource before constructing the annotation.
  3. 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

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


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)