{"record":{"id":"f2116639c4514f3d","repo":"microsoft/aspire","slug":"error-message-cannot-be-null-or-empty","errorCode":null,"errorMessage":"Error message cannot be null or empty.","messagePattern":"Error message cannot be null or empty\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/IInteractionService.cs","lineNumber":857,"sourceCode":"    public required CancellationToken CancellationToken { get; init; }\n\n    /// <summary>\n    /// Gets the service provider for resolving services during validation.\n    /// </summary>\n    public required IServiceProvider Services { get; init; }\n\n    /// <summary>\n    /// Adds a validation error for the specified input.\n    /// </summary>\n    /// <param name=\"input\">The input to add a validation error for.</param>\n    /// <param name=\"errorMessage\">The error message to add.</param>\n    public void AddValidationError(InteractionInput input, string errorMessage)\n    {\n        ArgumentNullException.ThrowIfNull(input, nameof(input));\n\n        if (string.IsNullOrEmpty(errorMessage))\n        {\n            throw new ArgumentException(\"Error message cannot be null or empty.\", nameof(errorMessage));\n        }\n\n        input.ValidationErrors.Add(errorMessage);\n        HasErrors = true;\n    }\n\n    /// <summary>\n    /// Adds a validation error for the input with the specified name.\n    /// </summary>\n    /// <param name=\"inputName\">The name of the input to add a validation error for.</param>\n    /// <param name=\"errorMessage\">The error message to add.</param>\n    [AspireExport(\"InputsDialogValidationContext.addValidationError\", MethodName = \"addValidationError\")]\n    public void AddValidationError(string inputName, string errorMessage)\n    {\n        AddValidationError(Inputs[inputName], errorMessage);\n    }\n}\n","sourceCodeStart":839,"sourceCodeEnd":875,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/IInteractionService.cs#L839-L875","documentation":"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.","triggerScenarios":"Calling AddValidationError(input, null) or AddValidationError(input, \"\") or passing a whitespace/empty result of a variable or function producing the message.","commonSituations":"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.","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."],"exampleFix":"// before\nprompt.AddValidationError(input, string.Empty);\n// after\nprompt.AddValidationError(input, \"A value for this input is required.\");","handlingStrategy":"validation","validationCode":"if (!string.IsNullOrWhiteSpace(errorMessage))\n{\n    prompt.AddValidationError(input, errorMessage);\n}","typeGuard":"static bool IsValidMessage(string? m) => !string.IsNullOrWhiteSpace(m);","tryCatchPattern":"try\n{\n    prompt.AddValidationError(input, errorMessage);\n}\ncatch (ArgumentException ex) when (ex.ParamName == nameof(errorMessage))\n{\n    logger.LogError(ex, \"Skipped empty validation message for {Input}\", input.Name);\n}","preventionTips":["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."],"tags":["argument-empty","validation","interaction"],"backgroundTag":"empty-required-field","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"}