microsoft/aspire · error · ArgumentNullException
Value cannot be null. (Parameter 'launchProfileName')
Error message
Value cannot be null. (Parameter 'launchProfileName')
What it means
DefaultLaunchProfileAnnotation's constructor performs a null check on launchProfileName and throws ArgumentNullException when it is null. The annotation exists to designate which launch settings profile a project resource should use, so a null name is meaningless.
Solutions
- Provide a concrete profile name, e.g. "https" or "http".
- Check the source value for null/empty before constructing the annotation and fall back to a default.
- If the profile is optional, skip adding the annotation rather than adding one with a null name.
Example fix
// before
var profile = Environment.GetEnvironmentVariable("LAUNCH_PROFILE");
builder.AddAnnotation(new DefaultLaunchProfileAnnotation(profile)); // null -> throws
// after
var profile = Environment.GetEnvironmentVariable("LAUNCH_PROFILE") ?? "https";
builder.AddAnnotation(new DefaultLaunchProfileAnnotation(profile)); Defensive patterns
Strategy: validation
Validate before calling
if (string.IsNullOrEmpty(profileName)) profileName = "https"; builder.AddAnnotation(new DefaultLaunchProfileAnnotation(profileName));
Try / catch
try { builder.AddAnnotation(new DefaultLaunchProfileAnnotation(profileName)); }
catch (ArgumentNullException) { /* skip or default profile */ } Prevention
- Coalesce nullable profile sources to a default before constructing annotations
- Use string interpolation only after a null check
- Avoid passing environment/config lookups directly into required parameters
When it happens
Trigger: Constructing new DefaultLaunchProfileAnnotation(null) — typically by passing a variable or configuration lookup that resolved to null, e.g. environment["PROFILE"] or an optional parameter.
Common situations: Reading the profile name from configuration/environment that is not set, refactoring a method to return a nullable string, or deserializing options where the field is missing.
Related errors
- Value cannot be null. (Parameter 'iconName')
- adminPassword
- ArgumentNullException for parameter 'args' (args is null).
- ArgumentNullException for parameter 'args' (args is null).
- ArgumentNullException for parameter 'callback' (callback is…
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/63d87ea052c2784d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/DefaultLaunchProfileAnnotation.cs:14
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Diagnostics;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// An annotation that specifies the default launch profile for a resource.
/// </summary>
[DebuggerDisplay("Type = {GetType().Name,nq}, LaunchProfileName = {LaunchProfileName}")]
public sealed class DefaultLaunchProfileAnnotation(string launchProfileName) : IResourceAnnotation
{
private readonly string _launchProfileName = launchProfileName ?? throw new ArgumentNullException(nameof(launchProfileName));
/// <summary>
/// The name of the default launch profile.
/// </summary>
public string LaunchProfileName => _launchProfileName;
}
View on GitHub (pinned to 25830f84bd)