microsoft/aspire · error · ArgumentException
Error message cannot be null or empty.
Error message
Error message cannot be null or empty.
What it means
InteractionBuilder.AddValidationError validates that errorMessage is non-null and non-empty before attaching it to the input's ValidationErrors. An empty message would produce useless UI feedback, so ArgumentException is thrown eagerly.
Solutions
- Pass a descriptive, non-empty message such as "Value is required".
- Guard caller-supplied messages before calling AddValidationError.
- If the message may be absent, skip the call instead of adding an empty error.
Example fix
// before prompt.AddValidationError(input, string.Empty); // after prompt.AddValidationError(input, "A value for this input is required.");
Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(errorMessage))
{
prompt.AddValidationError(input, errorMessage);
} Type guard
static bool IsValidMessage(string? m) => !string.IsNullOrWhiteSpace(m);
Try / catch
try
{
prompt.AddValidationError(input, errorMessage);
}
catch (ArgumentException ex) when (ex.ParamName == nameof(errorMessage))
{
logger.LogError(ex, "Skipped empty validation message for {Input}", input.Name);
} Prevention
- Always pass literal, descriptive messages rather than interpolated possibly-empty strings.
- Validate resource strings resolve before using them as messages.
- Wrap dynamic message construction in a helper that guarantees non-empty output.
When it happens
Trigger: Calling AddValidationError(input, null) or AddValidationError(input, "") or passing a whitespace/empty result of a variable or function producing the message.
Common situations: Building the message via string interpolation that yields empty (e.g. from a missing resource string); passing through a caller-supplied message that was not checked.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- Must not be null or empty
- Must not be null or empty
- Must not be null or whitespace
- Must not be null or whitespace
- Submitted files for input
AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16).
Data as JSON: /api/errors/f2116639c4514f3d.
Report an issue: GitHub.
Appendix: source
Thrown at src/Aspire.Hosting/IInteractionService.cs:857
public required CancellationToken CancellationToken { get; init; }
/// <summary>
/// Gets the service provider for resolving services during validation.
/// </summary>
public required IServiceProvider Services { get; init; }
/// <summary>
/// Adds a validation error for the specified input.
/// </summary>
/// <param name="input">The input to add a validation error for.</param>
/// <param name="errorMessage">The error message to add.</param>
public void AddValidationError(InteractionInput input, string errorMessage)
{
ArgumentNullException.ThrowIfNull(input, nameof(input));
if (string.IsNullOrEmpty(errorMessage))
{
throw new ArgumentException("Error message cannot be null or empty.", nameof(errorMessage));
}
input.ValidationErrors.Add(errorMessage);
HasErrors = true;
}
/// <summary>
/// Adds a validation error for the input with the specified name.
/// </summary>
/// <param name="inputName">The name of the input to add a validation error for.</param>
/// <param name="errorMessage">The error message to add.</param>
[AspireExport("InputsDialogValidationContext.addValidationError", MethodName = "addValidationError")]
public void AddValidationError(string inputName, string errorMessage)
{
AddValidationError(Inputs[inputName], errorMessage);
}
}
View on GitHub (pinned to 25830f84bd)