{"record":{"id":"d36462c6bcab06ad","repo":"microsoft/aspire","slug":"object-value-cannot-be-null-argumentnullexception-parent-d36462","errorCode":null,"errorMessage":"Object value cannot be null (ArgumentNullException: parent)","messagePattern":"Object value cannot be null \\(ArgumentNullException: parent\\)","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceConnectionResource.cs","lineNumber":35,"sourceCode":"{\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"AzureConnectorNamespaceConnectionResource\"/> class.\n    /// </summary>\n    /// <param name=\"name\">The Aspire resource name.</param>\n    /// <param name=\"connectionName\">The Azure connector connection name.</param>\n    /// <param name=\"connectorName\">The connector catalog name.</param>\n    /// <param name=\"displayName\">The friendly display name shown for the connection.</param>\n    /// <param name=\"parent\">The parent connector namespace resource.</param>\n    public AzureConnectorNamespaceConnectionResource(string name, string connectionName, string connectorName, string? displayName, AzureConnectorNamespaceResource parent)\n        : base(name)\n    {\n        ArgumentException.ThrowIfNullOrWhiteSpace(connectionName);\n        ArgumentException.ThrowIfNullOrWhiteSpace(connectorName);\n\n        ConnectionName = connectionName;\n        ConnectorName = connectorName;\n        DisplayName = displayName;\n        Parent = parent ?? throw new ArgumentNullException(nameof(parent));\n        BicepIdentifier = ConnectorNamespaceBicepIdentifiers.CreateConnection(parent.Name, name);\n    }\n\n    /// <summary>\n    /// Gets the Azure connector connection name.\n    /// </summary>\n    public string ConnectionName { get; }\n\n    /// <summary>\n    /// Gets the connector catalog name.\n    /// </summary>\n    public string ConnectorName { get; }\n\n    /// <summary>\n    /// Gets the friendly display name shown for the connection.\n    /// </summary>\n    public string? DisplayName { get; }\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ConnectorNamespace/AzureConnectorNamespaceConnectionResource.cs#L17-L53","documentation":"The AzureConnectorNamespaceConnectionResource constructor requires a non-null parent Connector Namespace resource; the parent's Name is used to build the connection's Bicep identifier. Passing null parent throws ArgumentNullException.","triggerScenarios":"Constructing AzureConnectorNamespaceConnectionResource directly with parent = null, e.g. calling AddConnection with a builder whose Resource is null or building the connection before the namespace resource exists.","commonSituations":"Manual provisioning-model construction bypassing AddConnection; dependency-injection or factory code that resolves the parent lazily and yields null; copy-pasted resource constructors where the parent argument was dropped.","solutions":["Use the AddConnection extension on the Connector Namespace resource builder, which supplies the parent automatically","Build the namespace with AddAzureConnectorNamespace before creating connections","Fix factory/DI code so the parent resource is resolved before connection creation"],"exampleFix":"// before\nvar conn = new AzureConnectorNamespaceConnectionResource(name, connectionName, displayName, null!, connectorName);\n// after\nnsBuilder.AddConnection(name, connectorName, options => options.ConnectionName = connectionName);","handlingStrategy":"validation","validationCode":"if (parent is null) throw new InvalidOperationException(\"Connector Namespace parent must be built before creating connections.\");","typeGuard":"bool canCreate = parent is not null;","tryCatchPattern":"try { new AzureConnectorNamespaceConnectionResource(...); } catch (ArgumentNullException ex) when (ex.ParamName == \"parent\") { /* use AddConnection instead */ }","preventionTips":["Use the AddConnection builder extension rather than direct construction","Ensure the namespace builder exists before wiring connections","Avoid factories that can return null parents"],"tags":["azure","connector-namespace","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"}