{"record":{"id":"c159ea4acd75eb00","repo":"microsoft/aspire","slug":"parent-azureservicebustopicresource","errorCode":null,"errorMessage":"parent","messagePattern":"parent","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusTopicResource.cs","lineNumber":42,"sourceCode":"[AspireExport(ExposeProperties = true)]\npublic class AzureServiceBusTopicResource(string name, string topicName, AzureServiceBusResource parent)\n    : Resource(name), IResourceWithParent<AzureServiceBusResource>, IResourceWithConnectionString, IResourceWithAzureFunctionsConfig\n{\n    private string _topicName = ThrowIfNullOrEmpty(topicName);\n\n    /// <summary>\n    /// The topic name.\n    /// </summary>\n    public string TopicName\n    {\n        get => _topicName;\n        set => _topicName = ThrowIfNullOrEmpty(value, nameof(topicName));\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 Topic.\n    /// </summary>\n    public ReferenceExpression ConnectionStringExpression => Parent.GetConnectionString(TopicName, null);\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>\n    public TimeSpan? DefaultMessageTimeToLive { get; set; }\n\n    /// <summary>\n    /// ISO 8601 timeSpan structure that defines the duration of the duplicate\n    /// detection history. The default value is 10 minutes.\n    /// </summary>","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusTopicResource.cs#L24-L60","documentation":"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.","triggerScenarios":"Constructing AzureServiceBusTopicResource directly with a null parent argument instead of using builder.AddAzureServiceBusTopic.","commonSituations":"Custom extension methods that resolve the parent namespace dynamically and pass a null resource; tests that construct topic resources without a backing AzureServiceBusResource.","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."],"exampleFix":"// before\nvar topic = new AzureServiceBusTopicResource(\"orders\", \"orders-topic\", GetBusMaybeNull());\n\n// after\nvar bus = builder.AddAzureServiceBus(\"bus\");\nvar topic = bus.AddTopic(\"orders\", \"orders-topic\");","handlingStrategy":"validation","validationCode":"if (busResource is null) throw new InvalidOperationException(\"Create the Azure Service Bus namespace before adding topics.\");","typeGuard":"if (busResource is not null) { var topic = new AzureServiceBusTopicResource(name, topicName, busResource); }","tryCatchPattern":null,"preventionTips":["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."],"tags":["argument-null","azure-servicebus","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"}