{"record":{"id":"5548d0c95b305b60","repo":"microsoft/aspire","slug":"parent","errorCode":null,"errorMessage":"parent","messagePattern":"parent","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusQueueResource.cs","lineNumber":42,"sourceCode":"[AspireExport(ExposeProperties = true)]\npublic class AzureServiceBusQueueResource(string name, string queueName, AzureServiceBusResource parent)\n    : Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig\n{\n    private string _queueName = ThrowIfNullOrEmpty(queueName);\n\n    /// <summary>\n    /// The queue name.\n    /// </summary>\n    public string QueueName\n    {\n        get => _queueName;\n        set => _queueName = ThrowIfNullOrEmpty(value, nameof(queueName));\n    }\n\n    /// <summary>\n    /// Gets the parent Azure Service Bus resource.\n    /// </summary>\n    public AzureServiceBusResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));\n\n    /// <summary>\n    /// Gets the connection string expression for the Azure Service Bus Queue.\n    /// </summary>\n    public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(QueueName, null);\n\n    /// <summary>\n    /// A value that indicates whether this queue has dead letter support when\n    /// a message expires.\n    /// </summary>\n    public bool? DeadLetteringOnMessageExpiration { get; set; }\n\n    /// <summary>\n    /// ISO 8601 default message timespan to live value. This is the duration\n    /// after which the message expires, starting from when the message is\n    /// sent to Service Bus. This is the default value used when TimeToLive is\n    /// not set on a message itself.\n    /// </summary>","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusQueueResource.cs#L24-L60","documentation":"AzureServiceBusQueueResource's constructor requires the parent AzureServiceBusResource (the namespace it belongs to) and throws ArgumentNullException when parent is null. The queue's ConnectionStringExpression is built from the parent, so a queue cannot exist without it.","triggerScenarios":"Calling new AzureServiceBusQueueResource(..., parent: null) — typically via custom code or tests — instead of creating queues with builder.AddServiceBusQueue on the Service Bus resource builder.","commonSituations":"Hand-building queue resources in unit tests and forgetting the parent; reflection/serialization instantiating the type incorrectly; refactors dropping a constructor argument.","solutions":["Create queues via the API: parent.AddServiceBusQueue(\"queue\") on the AzureServiceBusResource builder, not by direct construction.","If constructing directly, pass the non-null AzureServiceBusResource as the parent argument.","Null-check the parent in your factory code before constructing the queue resource."],"exampleFix":"// before\nvar queue = new AzureServiceBusQueueResource(\"q\", null!);\n// after\nvar queue = new AzureServiceBusQueueResource(\"q\", serviceBusResource);","handlingStrategy":"validation","validationCode":"if (parent is null)\n{\n    throw new ArgumentNullException(nameof(parent), \"Queue resources require their parent AzureServiceBusResource.\");\n}\nvar queue = new AzureServiceBusQueueResource(\"q\", parent);","typeGuard":"static AzureServiceBusResource? TryGetParent(IResource? r) => r as AzureServiceBusResource;","tryCatchPattern":null,"preventionTips":["Create queues via AddServiceBusQueue on the Service Bus builder instead of direct construction.","In tests, always supply the real parent resource from the builder.","Null-check parents before constructing child resources."],"tags":["azure","servicebus","queue","null-argument"],"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"}