microsoft/aspire · error · ArgumentNullException

Value cannot be null. (Parameter 'parent')

Error message

Value cannot be null. (Parameter 'parent')

What it means

MilvusDatabaseResource is a child resource that must be attached to a MilvusServerResource. The primary constructor parameter 'parent' is validated with an ArgumentNullException guard, so constructing the database resource with a null parent throws immediately. This is an internal invariant: a database resource is meaningless without its server container.

Solutions

  1. Ensure the MilvusServerResource is created before AddDatabase is called and pass that instance as parent.
  2. If writing a custom extension, resolve the parent from builder.ApplicationBuilder.Resources and null-check it before constructing MilvusDatabaseResource.
  3. Use the public AddDatabase extension on IResourceBuilder<MilvusServerResource> instead of constructing MilvusDatabaseResource manually.

Example fix

// before
var db = new MilvusDatabaseResource("db", "mydb", GetParentMaybeNull());
// after
var parent = GetParent() ?? throw new InvalidOperationException("Milvus server resource not found");
var db = new MilvusDatabaseResource("db", "mydb", parent);
Defensive patterns

Strategy: validation

Validate before calling

if (parent is null) throw new InvalidOperationException("Milvus server resource must be created before adding a database");
var db = new MilvusDatabaseResource(name, databaseName, parent);

Type guard

bool HasParent(MilvusServerResource? p) => p is not null;

Try / catch

try { var db = new MilvusDatabaseResource(name, databaseName, parent); } catch (ArgumentNullException ex) when (ex.ParamName == "parent") { /* resolve parent server resource and retry */ }

Prevention

When it happens

Trigger: Calling the MilvusDatabaseResource constructor directly (or an AddDatabase-style extension passing a null parent reference) with parent == null.

Common situations: Custom hosting extension code that resolves the parent server resource from a builder or reference and gets null (e.g. wrong resource type cast or a reference that was never initialized); hand-rolled resource models copying the Aspire pattern.

Related errors


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

Appendix: source

Thrown at src/Aspire.Hosting.Milvus/MilvusDatabaseResource.cs:25

using Aspire.Hosting.Milvus;

namespace Aspire.Hosting.ApplicationModel;

/// <summary>
/// A resource that represents a Milvus database. This is a child resource of a <see cref="MilvusServerResource"/>.
/// </summary>
/// <param name="name">The name of the resource.</param>
/// <param name="databaseName">The database name.</param>
/// <param name="parent">The Milvus parent resource associated with this database.</param>
/// <ats-summary>A resource that represents a Milvus database. This is a child resource of a <ats-see cref="!:type:MilvusServerResource" />.</ats-summary>
[DebuggerDisplay("Type = {GetType().Name,nq}, Name = {Name}, Database = {DatabaseName}")]
[AspireExport(ExposeProperties = true)]
public class MilvusDatabaseResource(string name, string databaseName, MilvusServerResource parent) : Resource(name), IResourceWithParent<MilvusServerResource>, IResourceWithConnectionString
{
    /// <summary>
    /// Gets the parent Milvus container resource.
    /// </summary>
    public MilvusServerResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));

    /// <summary>
    /// Gets the connection string expression for the Milvus database.
    /// </summary>
    /// <remarks>
    /// Format: <c>Endpoint={uri};Key={token};Database={DatabaseName}</c>.
    /// </remarks>
    public ReferenceExpression ConnectionStringExpression =>
       ReferenceExpression.Create($"{Parent};Database={DatabaseName}");

    /// <summary>
    /// Gets the database name.
    /// </summary>
    public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);

    private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)
    {
        ArgumentException.ThrowIfNullOrEmpty(argument, paramName);

View on GitHub (pinned to 25830f84bd)