microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'innerResource')
Error message
Value cannot be null. (Parameter 'innerResource')
What it means
AzureCosmosDBEmulatorResource wraps an AzureCosmosDBResource in InnerResource and throws ArgumentNullException('innerResource') when given null. The wrapper gets its name and its entire annotation collection from the inner resource, so it cannot function without one.
Solutions
- Use the fluent API: builder.AddAzureCosmosDB("cosmos").RunAsEmulator(), which always supplies the inner resource.
- If constructing manually, pass the AzureCosmosDBResource instance returned from AddAzureCosmosDB.
- Guard the resource variable for null before creating the wrapper.
Example fix
// before
var emulator = new AzureCosmosDBEmulatorResource(null!);
// after
var cosmos = builder.AddAzureCosmosDB("cosmos");
var emulator = new AzureCosmosDBEmulatorResource(cosmos.Resource); Defensive patterns
Strategy: validation
Validate before calling
if (innerResource is null) throw new InvalidOperationException("Emulator wrapper requires a non-null AzureCosmosDBResource."); Type guard
static bool IsWrapped(Builder b) => b.Resource is AzureCosmosDBResource;
Try / catch
try { var emulator = new AzureCosmosDBEmulatorResource(cosmos.Resource); } catch (ArgumentNullException ex) when (ex.ParamName == "innerResource") { /* create resource via AddAzureCosmosDB first */ } Prevention
- Prefer AddAzureCosmosDB(...).RunAsEmulator() over manual construction.
- Never pass a possibly-null resource into the wrapper.
- In tests, build the resource via the extension API first.
When it happens
Trigger: Calling new AzureCosmosDBEmulatorResource(null) directly, or invoking RunAsEmulator/RunAsClassicEmulator on a builder whose Resource is null.
Common situations: Manual instantiation in tests or custom tooling instead of using AddAzureCosmosDB(...).RunAsEmulator(); reflection-based construction passing default values.
Related errors
- ConnectionStringAvailableEvent was published for the
- CosmosClient is not initialized.
- Count must be between 1 and 250.
- innerResource
- The Data Explorer endpoint is only available when using the…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/15a110e0209b4f6b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting.Azure.CosmosDB/AzureCosmosDBEmulatorResource.cs:15
// 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="AzureCosmosDBResource" /> in a type that exposes container extension methods.
/// </summary>
/// <param name="innerResource">The inner resource used to store annotations.</param>
public class AzureCosmosDBEmulatorResource(AzureCosmosDBResource innerResource)
: ContainerResource(innerResource.Name)
{
internal AzureCosmosDBResource InnerResource { get; } = innerResource ?? throw new ArgumentNullException(nameof(innerResource));
/// <inheritdoc />
public override ResourceAnnotationCollection Annotations => InnerResource.Annotations;
}
View on GitHub (pinned to 25830f84bd)