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
- Pass a valid AzureConnectorNamespaceMcpServerConfigResource instance as parent
- Construct the resource via the extension methods (WithIdentityAccessPolicy) instead of direct construction
- 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
- Prefer extension methods (WithIdentityAccessPolicy) over direct construction
- Null-check parent resources returned from factories
- Keep resource construction inside the app-model APIs
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
- Object value cannot be null (ArgumentNullException: parent)
- Object value cannot be null (ArgumentNullException: parent)
- Value cannot be null. (Parameter 'config')
- Value cannot be null. (Parameter 'parent')
- Value cannot be null. (Parameter 'parent')
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)