microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'innerResource')
Error message
Value cannot be null. (Parameter 'innerResource')
What it means
AzureEventHubsEmulatorResource wraps an inner AzureEventHubsResource and stores it in a readonly field with a null guard. A null inner resource would leave the emulator resource with no Name, no annotations, and no backing configuration, so it is rejected at construction time.
Solutions
- Pass the existing AzureEventHubsResource instance when constructing the emulator resource
- Prefer the RunAsEmulator extension, which wires the inner resource automatically
- Fix any test fixture or deserializer that fails to supply the inner resource
Example fix
// before
var emulator = new AzureEventHubsEmulatorResource("emulator", null);
// after
var emulator = new AzureEventHubsEmulatorResource("emulator", eventHubsResource); Defensive patterns
Strategy: type-guard
Validate before calling
if (eventHubsResource is null) throw new ArgumentNullException(nameof(eventHubsResource));
Type guard
static bool CanCreateEmulatorResource(AzureEventHubsResource? inner) => inner is not null;
Try / catch
try { var emulator = new AzureEventHubsEmulatorResource(name, inner); }
catch (ArgumentNullException ex) when (ex.ParamName == "innerResource") { /* supply the real resource */ } Prevention
- Use RunAsEmulator instead of constructing the emulator resource directly
- Keep a single reference to the underlying resource in test fixtures
- Enable nullable reference types in test projects
When it happens
Trigger: Directly constructing AzureEventHubsEmulatorResource with a null innerResource — e.g. manual construction in tests or tooling that should be using the RunAsEmulator extension instead.
Common situations: Unit tests instantiating the emulator resource directly; custom harness code building the resource graph by hand; refactoring that removed the original resource before creating the emulator wrapper.
Related errors
- Value cannot be null. (Parameter 'sourcePath')
- innerResource
- The Azure Event Hubs resource is already configured to run…
- The configuration file mount could not be parsed.
- Value cannot be null. (Parameter 'innerResource')
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/d3b3a9cf96442b0b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.EventHubs/AzureEventHubsEmulatorResource.cs:21
using Aspire.Hosting.ApplicationModel;
namespace Aspire.Hosting.Azure;
/// <summary>
/// Wraps an <see cref="AzureEventHubsResource" /> in a type that exposes container extension methods.
/// </summary>
/// <param name="innerResource">The inner resource used to store annotations.</param>
public class AzureEventHubsEmulatorResource(AzureEventHubsResource innerResource)
: ContainerResource(innerResource.Name), IResource
{
// The path to the emulator configuration file in the container.
// The path to the emulator configuration files in the container.
internal const string EmulatorConfigFilesPath = "/Eventhubs_Emulator/ConfigFiles";
// The path to the emulator configuration file in the container.
internal const string EmulatorConfigJsonFile = "Config.json";
private readonly AzureEventHubsResource _innerResource = innerResource ?? throw new ArgumentNullException(nameof(innerResource));
/// <inheritdoc/>
public override string Name => _innerResource.Name;
/// <inheritdoc />
public override ResourceAnnotationCollection Annotations => _innerResource.Annotations;
}
View on GitHub (pinned to 25830f84bd)