microsoft/aspire · error · ArgumentNullException
parent
Error message
parent
What it means
The AzureServiceBusSubscriptionResource constructor throws ArgumentNullException when the parent topic resource is null. The library requires every subscription resource to be attached to a valid AzureServiceBusTopicResource so its connection string can be derived via the parent hierarchy.
Solutions
- Pass the AzureServiceBusTopicResource you created with AddAzureServiceBusTopic directly into the constructor or subscription extension call.
- Check that the topic-creating call actually returned a non-null resource before constructing the subscription.
- Prefer the AddAzureServiceBusSubscription extension over manual construction.
Example fix
// before
var sub = new AzureServiceBusSubscriptionResource("orders-sub", "orders", GetTopicMaybeNull());
// after
var topic = builder.AddAzureServiceBusTopic("orders", "orders-topic");
var sub = new AzureServiceBusSubscriptionResource("orders-sub", "orders", topic.Resource); Defensive patterns
Strategy: validation
Validate before calling
if (topicResource is null) throw new InvalidOperationException("Topic resource must be created before the subscription."); Type guard
if (topicResource is not null) { var sub = new AzureServiceBusSubscriptionResource(name, subName, topicResource); } Prevention
- Always create topics via AddAzureServiceBusTopic before adding subscriptions.
- Never pass lookup results that can be null directly into resource constructors.
- Prefer extension methods over direct resource construction.
When it happens
Trigger: Calling the AzureServiceBusSubscriptionResource constructor directly (or a low-level extension/API that forwards to it) with a null AzureServiceBusTopicResource parent argument.
Common situations: Hand-constructing subscription resources in custom extension methods or tests; passing the result of a lookup that returned null (e.g. resource not found in the model) into the constructor.
Related errors
- parent
- parent
- ArgumentNullException for parameter 'callback' (callback is…
- ArgumentNullException for parameter 'resource' (resource is…
- ArgumentNullException for parameter 'services' (services is…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/4bbb42445f1656f7.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusSubscriptionResource.cs:42
[AspireExport(ExposeProperties = true)]
public class AzureServiceBusSubscriptionResource(string name, string subscriptionName, AzureServiceBusTopicResource parent)
: Resource(name), IResourceWithParent<AzureServiceBusTopicResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _subscriptionName = ThrowIfNullOrEmpty(subscriptionName);
/// <summary>
/// The subscription name.
/// </summary>
public string SubscriptionName
{
get => _subscriptionName;
set => _subscriptionName = ThrowIfNullOrEmpty(value, nameof(subscriptionName));
}
/// <summary>
/// Gets the parent Azure Service Bus Topic resource.
/// </summary>
public AzureServiceBusTopicResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));
/// <summary>
/// Gets the connection string expression for the Azure Service Bus Subscription.
/// </summary>
public ReferenceExpression ConnectionStringExpression => Parent.Parent.GetConnectionString(Parent.TopicName, SubscriptionName);
/// <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)