microsoft/aspire · error · ArgumentNullException
parent
Error message
parent
What it means
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.
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.
Example fix
// before
var queue = new AzureServiceBusQueueResource("q", null!);
// after
var queue = new AzureServiceBusQueueResource("q", serviceBusResource); Defensive patterns
Strategy: validation
Validate before calling
if (parent is null)
{
throw new ArgumentNullException(nameof(parent), "Queue resources require their parent AzureServiceBusResource.");
}
var queue = new AzureServiceBusQueueResource("q", parent); Type guard
static AzureServiceBusResource? TryGetParent(IResource? r) => r as AzureServiceBusResource;
Prevention
- 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.
When it happens
Trigger: Calling new AzureServiceBusQueueResource(..., parent: null) — typically via custom code or tests — instead of creating queues with builder.AddServiceBusQueue on the Service Bus resource builder.
Common situations: Hand-building queue resources in unit tests and forgetting the parent; reflection/serialization instantiating the type incorrectly; refactors dropping a constructor argument.
Related errors
- innerResource
- A QueueClient could not be configured. Ensure valid…
- Object value cannot be null (ArgumentNullException: parent)
- Object value cannot be null (ArgumentNullException: parent)
- ' ' is not a valid value.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/5548d0c95b305b60.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusQueueResource.cs:42
[AspireExport(ExposeProperties = true)]
public class AzureServiceBusQueueResource(string name, string queueName, AzureServiceBusResource parent)
: Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _queueName = ThrowIfNullOrEmpty(queueName);
/// <summary>
/// The queue name.
/// </summary>
public string QueueName
{
get => _queueName;
set => _queueName = ThrowIfNullOrEmpty(value, nameof(queueName));
}
/// <summary>
/// Gets the parent Azure Service Bus resource.
/// </summary>
public AzureServiceBusResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));
/// <summary>
/// Gets the connection string expression for the Azure Service Bus Queue.
/// </summary>
public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(QueueName, null);
/// <summary>
/// A value that indicates whether this queue has dead letter support when
/// a message expires.
/// </summary>
public bool? DeadLetteringOnMessageExpiration { get; set; }
/// <summary>
/// ISO 8601 default message timespan to live value. This is the duration
/// after which the message expires, starting from when the message is
/// sent to Service Bus. This is the default value used when TimeToLive is
/// not set on a message itself.
/// </summary>View on GitHub (pinned to 25830f84bd)