microsoft/aspire · error · ArgumentNullException

Object value cannot be null (ArgumentNullException: parent)

Error message

Object value cannot be null (ArgumentNullException: parent)

What it means

The AzureConnectorNamespaceConnectionAccessPolicyResource constructor requires a non-null parent Connector Namespace resource and throws ArgumentNullException when parent is null. The parent is needed to derive the Bicep identifier and model the access policy as a child of the namespace.

Solutions

  1. Create access policies via the WithAccessPolicy extension on the Connector Namespace builder instead of constructing the resource directly
  2. Ensure the parent AzureConnectorNamespaceResource is built (AddAzureConnectorNamespace) before creating access policies
  3. Remove null-forgiving (!) operators and let the compiler flag the null parent

Example fix

// before
var policy = new AzureConnectorNamespaceConnectionAccessPolicyResource(name, null!, objectId, tenantId, identityResource);
// after
var ns = builder.AddAzureConnectorNamespace("ns");
ns.WithAccessPolicy(...); // parent supplied automatically
Defensive patterns

Strategy: validation

Validate before calling

if (parent is null) throw new InvalidOperationException("Build the Connector Namespace resource before creating access policies.");

Type guard

bool canCreate = parent is not null;

Try / catch

try { new AzureConnectorNamespaceConnectionAccessPolicyResource(...); } catch (ArgumentNullException ex) when (ex.ParamName == "parent") { /* fall back to WithAccessPolicy extension */ }

Prevention

When it happens

Trigger: Constructing AzureConnectorNamespaceConnectionAccessPolicyResource directly with a null parent argument, e.g. passing an uninitialized resource builder's Resource or a variable that was never assigned.

Common situations: Hand-authoring Bicep/provisioning model code instead of using the WithAccessPolicy extension; refactoring that moved resource creation before the namespace resource was built; nullability warnings suppressed with null-forgiving operators.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceConnectionAccessPolicyResource.cs:37

    private AzureConnectorNamespaceConnectionAccessPolicyResource(
        string name,
        string policyName,
        AzureConnectorNamespaceConnectionResource parent,
        string objectId,
        string tenantId,
        AzureUserAssignedIdentityResource? identityResource)
        : base(name)
    {
        ArgumentException.ThrowIfNullOrWhiteSpace(policyName);
        if (identityResource is null)
        {
            ArgumentException.ThrowIfNullOrWhiteSpace(objectId);
            ArgumentException.ThrowIfNullOrWhiteSpace(tenantId);
        }

        PolicyName = policyName;
        Parent = parent ?? throw new ArgumentNullException(nameof(parent));
        ObjectId = objectId;
        TenantId = tenantId;
        IdentityResource = identityResource;
        BicepIdentifier = name;
    }

    public string PolicyName { get; }

    public string ObjectId { get; }

    public string TenantId { get; }

    public AzureConnectorNamespaceConnectionResource Parent { get; }

    public AzureUserAssignedIdentityResource? IdentityResource { get; }

    public string BicepIdentifier { get; }

View on GitHub (pinned to 25830f84bd)