{"record":{"id":"d00598c8b8d5ffcd","repo":"microsoft/aspire","slug":"value-cannot-be-null-parameter-parent-milvusdatabaseresource","errorCode":null,"errorMessage":"Value cannot be null. (Parameter 'parent')","messagePattern":"Value cannot be null\\. \\(Parameter 'parent'\\)","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting.Milvus/MilvusDatabaseResource.cs","lineNumber":25,"sourceCode":"using Aspire.Hosting.Milvus;\n\nnamespace Aspire.Hosting.ApplicationModel;\n\n/// <summary>\n/// A resource that represents a Milvus database. This is a child resource of a <see cref=\"MilvusServerResource\"/>.\n/// </summary>\n/// <param name=\"name\">The name of the resource.</param>\n/// <param name=\"databaseName\">The database name.</param>\n/// <param name=\"parent\">The Milvus parent resource associated with this database.</param>\n/// <ats-summary>A resource that represents a Milvus database. This is a child resource of a <ats-see cref=\"!:type:MilvusServerResource\" />.</ats-summary>\n[DebuggerDisplay(\"Type = {GetType().Name,nq}, Name = {Name}, Database = {DatabaseName}\")]\n[AspireExport(ExposeProperties = true)]\npublic class MilvusDatabaseResource(string name, string databaseName, MilvusServerResource parent) : Resource(name), IResourceWithParent<MilvusServerResource>, IResourceWithConnectionString\n{\n    /// <summary>\n    /// Gets the parent Milvus container resource.\n    /// </summary>\n    public MilvusServerResource Parent { get; } = parent ?? throw new ArgumentNullException(nameof(parent));\n\n    /// <summary>\n    /// Gets the connection string expression for the Milvus database.\n    /// </summary>\n    /// <remarks>\n    /// Format: <c>Endpoint={uri};Key={token};Database={DatabaseName}</c>.\n    /// </remarks>\n    public ReferenceExpression ConnectionStringExpression =>\n       ReferenceExpression.Create($\"{Parent};Database={DatabaseName}\");\n\n    /// <summary>\n    /// Gets the database name.\n    /// </summary>\n    public string DatabaseName { get; } = ThrowIfNullOrEmpty(databaseName);\n\n    private static string ThrowIfNullOrEmpty([NotNull] string? argument, [CallerArgumentExpression(nameof(argument))] string? paramName = null)\n    {\n        ArgumentException.ThrowIfNullOrEmpty(argument, paramName);","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting.Milvus/MilvusDatabaseResource.cs#L7-L43","documentation":"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.","triggerScenarios":"Calling the MilvusDatabaseResource constructor directly (or an AddDatabase-style extension passing a null parent reference) with parent == null.","commonSituations":"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.","solutions":["Ensure the MilvusServerResource is created before AddDatabase is called and pass that instance as parent.","If writing a custom extension, resolve the parent from builder.ApplicationBuilder.Resources and null-check it before constructing MilvusDatabaseResource.","Use the public AddDatabase extension on IResourceBuilder<MilvusServerResource> instead of constructing MilvusDatabaseResource manually."],"exampleFix":"// before\nvar db = new MilvusDatabaseResource(\"db\", \"mydb\", GetParentMaybeNull());\n// after\nvar parent = GetParent() ?? throw new InvalidOperationException(\"Milvus server resource not found\");\nvar db = new MilvusDatabaseResource(\"db\", \"mydb\", parent);","handlingStrategy":"validation","validationCode":"if (parent is null) throw new InvalidOperationException(\"Milvus server resource must be created before adding a database\");\nvar db = new MilvusDatabaseResource(name, databaseName, parent);","typeGuard":"bool HasParent(MilvusServerResource? p) => p is not null;","tryCatchPattern":"try { var db = new MilvusDatabaseResource(name, databaseName, parent); } catch (ArgumentNullException ex) when (ex.ParamName == \"parent\") { /* resolve parent server resource and retry */ }","preventionTips":["Always create the MilvusServerResource via AddMilvus before AddDatabase.","Use extension methods instead of constructing resource types directly.","Null-check resolved parent references before resource construction."],"tags":["null-argument","milvus","resource-model"],"backgroundTag":"null-argument","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}