microsoft/aspire · error · ArgumentNullException
parent
Error message
parent
What it means
The AzureServiceBusTopicResource constructor throws ArgumentNullException when the parent Azure Service Bus namespace resource is null. A topic must belong to a valid AzureServiceBusResource so connection strings can be composed from the namespace.
Solutions
- Pass the AzureServiceBusResource created by AddAzureServiceBus as the parent.
- Verify the namespace resource variable is non-null before constructing the topic.
- Use the AddAzureServiceBusTopic extension method instead of manual construction.
Example fix
// before
var topic = new AzureServiceBusTopicResource("orders", "orders-topic", GetBusMaybeNull());
// after
var bus = builder.AddAzureServiceBus("bus");
var topic = bus.AddTopic("orders", "orders-topic"); Defensive patterns
Strategy: validation
Validate before calling
if (busResource is null) throw new InvalidOperationException("Create the Azure Service Bus namespace before adding topics."); Type guard
if (busResource is not null) { var topic = new AzureServiceBusTopicResource(name, topicName, busResource); } Prevention
- Build the namespace with AddAzureServiceBus first, then chain AddTopic.
- Avoid constructing resource types manually in app code.
- Null-check results of any resource lookup before use.
When it happens
Trigger: Constructing AzureServiceBusTopicResource directly with a null parent argument instead of using builder.AddAzureServiceBusTopic.
Common situations: Custom extension methods that resolve the parent namespace dynamically and pass a null resource; tests that construct topic resources without a backing AzureServiceBusResource.
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/c159ea4acd75eb00.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusTopicResource.cs:42
[AspireExport(ExposeProperties = true)]
public class AzureServiceBusTopicResource(string name, string topicName, AzureServiceBusResource parent)
: Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig
{
private string _topicName = ThrowIfNullOrEmpty(topicName);
/// <summary>
/// The topic name.
/// </summary>
public string TopicName
{
get => _topicName;
set => _topicName = ThrowIfNullOrEmpty(value, nameof(topicName));
}
/// <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 Topic.
/// </summary>
public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(TopicName, null);
/// <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>
public TimeSpan? DefaultMessageTimeToLive { get; set; }
/// <summary>
/// ISO 8601 timeSpan structure that defines the duration of the duplicate
/// detection history. The default value is 10 minutes.
/// </summary>View on GitHub (pinned to 25830f84bd)