microsoft/aspire · error · ArgumentNullException
innerResource
Error message
innerResource
What it means
The AzureServiceBusEmulatorResource constructor stores the real (provisioned) AzureServiceBusResource it wraps and throws ArgumentNullException when the innerResource argument is null. The emulator resource delegates Annotations to the inner resource, so null is invalid by construction.
Solutions
- Always construct via builder.RunAsEmulator() rather than new AzureServiceBusEmulatorResource(...) directly.
- If constructing manually, pass the non-null AzureServiceBusResource from the resource builder (builder.Resource).
- Guard with ArgumentNullException.ThrowIfNull in your own factory before calling the constructor.
Example fix
// before var emulator = new AzureServiceBusEmulatorResource(null!); // after var emulator = new AzureServiceBusEmulatorResource(builder.Resource);
Defensive patterns
Strategy: validation
Validate before calling
if (innerResource is null)
{
throw new ArgumentNullException(nameof(innerResource), "Provide the AzureServiceBusResource to wrap.");
}
var emulator = new AzureServiceBusEmulatorResource(innerResource); Type guard
static AzureServiceBusResource? TryGetInnerResource(IResource? r) => r as AzureServiceBusResource;
Prevention
- Prefer builder.RunAsEmulator() over direct construction of AzureServiceBusEmulatorResource.
- Pass builder.Resource (never null) when constructing manually.
- Null-check resources in test factories before constructing emulator resources.
When it happens
Trigger: Calling new AzureServiceBusEmulatorResource(null) — directly or via RunAsEmulator internals — instead of passing the AzureServiceBusResource returned by AddAzureServiceBus.
Common situations: Hand-constructing the emulator resource in tests or custom code and passing a null builder resource; reflection-based instantiation with missing arguments; refactor dropped the argument.
Related errors
- parent
- The Azure Service Bus resource is already configured to run…
- The configuration file mount could not be parsed.
- Dashboard endpoint is only available when running as an…
- Emulator currently does not support data lake.
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/6fbfa5199c95cf8d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.ServiceBus/AzureServiceBusEmulatorResource.cs:19
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.ApplicationModel;
namespace Aspire.Hosting.Azure;
/// <summary>
/// Wraps an <see cref="AzureServiceBusResource" /> in a type that exposes container extension methods.
/// </summary>
/// <param name="innerResource">The inner resource used to store annotations.</param>
public class AzureServiceBusEmulatorResource(AzureServiceBusResource innerResource) : ContainerResource(innerResource.Name), IResource
{
// The path to the emulator configuration files in the container.
internal const string EmulatorConfigFilesPath = "/ServiceBus_Emulator/ConfigFiles";
// The path to the emulator configuration file in the container.
internal const string EmulatorConfigJsonFile = "Config.json";
private readonly AzureServiceBusResource _innerResource = innerResource ?? throw new ArgumentNullException(nameof(innerResource));
/// <inheritdoc />
public override ResourceAnnotationCollection Annotations => _innerResource.Annotations;
}
View on GitHub (pinned to 25830f84bd)