{"record":{"id":"e9179d6debfb28b1","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-parent","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'parent')","messagePattern":"Value cannot be null\\. \\(Parameter 'parent'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceMcpAccessPolicyResource.cs","lineNumber":17,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nusing Aspire.Hosting.ApplicationModel;\nnamespace Aspire.Hosting.Azure;\n\ninternal sealed class AzureConnectorNamespaceMcpAccessPolicyResource : Resource, IResourceWithParent<AzureConnectorNamespaceMcpServerConfigResource>\n{\n    public AzureConnectorNamespaceMcpAccessPolicyResource(\n        string name,\n        AzureConnectorNamespaceMcpServerConfigResource parent,\n        string objectId,\n        string tenantId,\n        AzureConnectorNamespaceMcpAccessPolicyPrincipalType principalType)\n        : base(name)\n    {\n        Parent = parent ?? throw new ArgumentNullException(nameof(parent));\n        ObjectId = objectId;\n        TenantId = tenantId;\n        PrincipalType = principalType;\n        BicepIdentifier = name;\n    }\n\n    public AzureConnectorNamespaceMcpServerConfigResource Parent { get; }\n\n    public string ObjectId { get; }\n\n    public string TenantId { get; }\n\n    public AzureConnectorNamespaceMcpAccessPolicyPrincipalType PrincipalType { get; }\n\n    public string BicepIdentifier { get; }\n}\n","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceMcpAccessPolicyResource.cs#L1-L34","documentation":"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.","triggerScenarios":"Constructing AzureConnectorNamespaceMcpAccessPolicyResource directly (e.g. in tests or custom infrastructure code) and passing null for the parent parameter.","commonSituations":"Hand-building resources instead of using WithIdentityAccessPolicy/WithAccessPolicy; a factory or deserializer returning null for the parent before constructing the policy 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"],"exampleFix":"// before\nnew AzureConnectorNamespaceMcpAccessPolicyResource(name, null!, objectId, tenantId, principalType);\n// after\nvar config = namespaceResource.AddMcpServerConfig(\"config\");\nnew AzureConnectorNamespaceMcpAccessPolicyResource(name, config, objectId, tenantId, principalType);","handlingStrategy":"type-guard","validationCode":"ArgumentNullException.ThrowIfNull(parent);","typeGuard":"if (parent is null) return; // or throw with context before constructing","tryCatchPattern":"try { var policy = new AzureConnectorNamespaceMcpAccessPolicyResource(name, config, objectId, tenantId, principalType); }\ncatch (ArgumentNullException ex) when (ex.ParamName == \"parent\") { log.LogError(ex, \"MCP server config resource was null\"); }","preventionTips":["Prefer extension methods (WithIdentityAccessPolicy) over direct construction","Null-check parent resources returned from factories","Keep resource construction inside the app-model APIs"],"tags":["azure","null-argument","constructor"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}