microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'parent')

Error message

Value cannot be null. (Parameter 'parent')

What it means

The AzureConnectorNamespaceMcpAccessPolicyResource constructor requires a non-null parent AzureConnectorNamespaceMcpServerConfigResource and throws ArgumentNullException when it is null. The parent links the access policy to its MCP server config resource.

Solutions

  1. Pass a valid AzureConnectorNamespaceMcpServerConfigResource instance as parent
  2. Construct the resource via the extension methods (WithIdentityAccessPolicy) instead of direct construction
  3. Check the value producing the parent for a null-returning call

Example fix

// before
new AzureConnectorNamespaceMcpAccessPolicyResource(name, null!, objectId, tenantId, principalType);
// after
var config = namespaceResource.AddMcpServerConfig("config");
new AzureConnectorNamespaceMcpAccessPolicyResource(name, config, objectId, tenantId, principalType);
Defensive patterns

Strategy: type-guard

Validate before calling

ArgumentNullException.ThrowIfNull(parent);

Type guard

if (parent is null) return; // or throw with context before constructing

Try / catch

try { var policy = new AzureConnectorNamespaceMcpAccessPolicyResource(name, config, objectId, tenantId, principalType); }
catch (ArgumentNullException ex) when (ex.ParamName == "parent") { log.LogError(ex, "MCP server config resource was null"); }

Prevention

When it happens

Trigger: Constructing AzureConnectorNamespaceMcpAccessPolicyResource directly (e.g. in tests or custom infrastructure code) and passing null for the parent parameter.

Common situations: Hand-building resources instead of using WithIdentityAccessPolicy/WithAccessPolicy; a factory or deserializer returning null for the parent before constructing the policy resource.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceMcpAccessPolicyResource.cs:17

// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Hosting.ApplicationModel;
namespace Aspire.Hosting.Azure;

internal sealed class AzureConnectorNamespaceMcpAccessPolicyResource : Resource, IResourceWithParent<AzureConnectorNamespaceMcpServerConfigResource>
{
    public AzureConnectorNamespaceMcpAccessPolicyResource(
        string name,
        AzureConnectorNamespaceMcpServerConfigResource parent,
        string objectId,
        string tenantId,
        AzureConnectorNamespaceMcpAccessPolicyPrincipalType principalType)
        : base(name)
    {
        Parent = parent ?? throw new ArgumentNullException(nameof(parent));
        ObjectId = objectId;
        TenantId = tenantId;
        PrincipalType = principalType;
        BicepIdentifier = name;
    }

    public AzureConnectorNamespaceMcpServerConfigResource Parent { get; }

    public string ObjectId { get; }

    public string TenantId { get; }

    public AzureConnectorNamespaceMcpAccessPolicyPrincipalType PrincipalType { get; }

    public string BicepIdentifier { get; }
}

View on GitHub (pinned to 25830f84bd)