{"record":{"id":"79effa01ac4144bf","repo":"microsoft/aspire","slug":"catalog-name-cannot-be-null-or-whitespace","errorCode":null,"errorMessage":"Catalog name cannot be null or whitespace.","messagePattern":"Catalog name cannot be null or whitespace\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Ats/AspireValueAttribute.cs","lineNumber":33,"sourceCode":"/// <para>\n/// The <paramref name=\"catalogName\"/> becomes the root name of the generated value catalog in\n/// guest SDKs. Nested static types are emitted as nested namespaces or classes under that root.\n/// </para>\n/// <para>\n/// Exported values should be side-effect free and should not return handles or other runtime-bound\n/// ATS types.\n/// </para>\n/// </remarks>\n/// <param name=\"catalogName\">The root name of the generated value catalog.</param>\n[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, Inherited = false, AllowMultiple = false)]\npublic sealed class AspireValueAttribute(string catalogName) : Attribute\n{\n    /// <summary>\n    /// Gets the root name of the generated value catalog.\n    /// </summary>\n    public string CatalogName { get; } = !string.IsNullOrWhiteSpace(catalogName)\n        ? catalogName\n        : throw new ArgumentException(\"Catalog name cannot be null or whitespace.\", nameof(catalogName));\n\n    /// <summary>\n    /// Gets or sets an optional override for the exported value name.\n    /// </summary>\n    public string? Name { get; set; }\n}\n","sourceCodeStart":15,"sourceCodeEnd":40,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Ats/AspireValueAttribute.cs#L15-L40","documentation":"AspireValueAttribute's CatalogName property throws ArgumentException when the catalogName passed to the attribute constructor is null, empty, or whitespace. The catalog name is the root name of the generated value catalog and must be a real identifier for export naming. The attribute cannot function without it, so the library fails fast at construction.","triggerScenarios":"Calling new AspireValueAttribute(null), new AspireValueAttribute(\"\"), or new AspireValueAttribute(\"   \") — i.e., supplying a null/empty/whitespace-only catalog name to the attribute constructor.","commonSituations":"Programmatically constructing the attribute from config-driven data (e.g., a sourced name that is null because a config key was missing), string concatenation that produced an empty result, or a default string parameter left unset in source generators or scaffolding code.","solutions":["Pass a non-empty catalog name string to the AspireValueAttribute constructor.","If the name comes from configuration or another source, validate it with string.IsNullOrWhiteSpace before constructing the attribute.","Check that the value is not accidentally an uninitialized field or a defaulted optional parameter."],"exampleFix":"// before\n[AspireValue(\"\")]\n// after\n[AspireValue(\"MyCatalog\")]","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(catalogName))\n{\n    throw new ArgumentException(\"A non-empty catalog name is required.\", nameof(catalogName));\n}\nvar attr = new AspireValueAttribute(catalogName);","typeGuard":"bool HasCatalogName(string? s) => !string.IsNullOrWhiteSpace(s);","tryCatchPattern":null,"preventionTips":["Never pass user/config-sourced strings straight into the attribute without an IsNullOrWhiteSpace check.","Centralize catalog name constants so empty defaults cannot appear at call sites."],"tags":["argument-validation","attributes","null-or-empty"],"backgroundTag":"invalid-argument-value","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"}