microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'innerResource')

Error message

Value cannot be null. (Parameter 'innerResource')

What it means

AzureKustoEmulatorResource is a wrapper (projection) around an AzureKustoClusterResource. Its constructor requires the wrapped inner resource; passing null throws ArgumentNullException because the wrapper needs the inner resource's name and annotations.

Solutions

  1. Pass a valid, non-null AzureKustoClusterResource instance to the constructor.
  2. Ensure the code path creating the emulator wrapper runs after AddAzureKustoCluster has produced the resource.
  3. Guard the call site with a null check and a clear error before constructing the wrapper.
  4. Fix factory methods that can return null so they always return the built resource.

Example fix

// before
var emulator = new AzureKustoEmulatorResource(GetClusterMaybe());
// after
var inner = GetClusterMaybe() ?? throw new InvalidOperationException("Kusto cluster resource must be created before RunAsEmulator.");
var emulator = new AzureKustoEmulatorResource(inner);
Defensive patterns

Strategy: type-guard

Validate before calling

if (innerResource is null) throw new InvalidOperationException("Cluster resource must be built (AddAzureKustoCluster) before creating the emulator wrapper.");

Type guard

AzureKustoEmulatorResource? TryCreate(AzureKustoClusterResource? r) => r is null ? null : new AzureKustoEmulatorResource(r);

Try / catch

try { var emulator = new AzureKustoEmulatorResource(inner); }
catch (ArgumentNullException) { /* innerResource was null; build the cluster resource first */ }

Prevention

When it happens

Trigger: Constructing new AzureKustoEmulatorResource(null) — either directly or via extension code that passes an unbuilt/unresolved cluster resource.

Common situations: Custom extensions or tests creating emulator wrapper resources before the cluster resource has been constructed, or a factory returning null instead of the cluster resource.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/fecff9d4909a831e. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Hosting.Azure.Kusto/AzureKustoEmulatorResource.cs:18

// 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>
/// A resource that represents a Kusto emulator running as a container.
/// </summary>
public class AzureKustoEmulatorResource : ContainerResource
{
    /// <summary>
    /// Initializes a new instance of the <see cref="AzureKustoEmulatorResource"/> class.
    /// </summary>
    /// <param name="innerResource">The wrapped Kusto resource.</param>
    public AzureKustoEmulatorResource(AzureKustoClusterResource innerResource)
        : base(innerResource?.Name ?? throw new ArgumentNullException(nameof(innerResource)))
    {
        InnerResource = innerResource;
    }

    /// <inheritdoc />
    public override ResourceAnnotationCollection Annotations => InnerResource.Annotations;

    /// <summary>
    /// Gets the wrapped Kusto resource.
    /// </summary>
    internal AzureKustoClusterResource InnerResource { get; }
}

View on GitHub (pinned to 25830f84bd)