nopSolutions/nopCommerce · warning · NopException

(localized, formatted with languageName)

Error message

{textRequiredLocale} (localized, formatted with languageName)

What it means

ValidateTitleAndTextAsync throws NopException when 'text' is null/empty AFTER stripping HTML tags via Regex.Replace(text, "<.*?>", string.Empty). So an entity whose description is only HTML with no text content, or genuinely empty, fails the check. The message is the localized textRequiredLocale formatted with languageName.

Solutions

  1. Ensure the entity has meaningful text content (not only images/markup) in the target language before AI generation.
  2. Pre-check the stripped text length client-side and warn the user to add body text.
  3. If only media is present, add a caption/alt-derived text so the stripped value is non-empty.

Example fix

// before
var (t,k,d) = await _aiService.CreateMetaTagsAsync(entity, languageId); // throws if body empty

// after
var body = languageId == 0 ? entity.Description : await _localizationService.GetLocalizedAsync(entity, e => e.Description, languageId, false);
if (string.IsNullOrWhiteSpace(Regex.Replace(body ?? string.Empty, "<.*?>", string.Empty)))
    return; // ask user to add description text first
Defensive patterns

Strategy: validation

Validate before calling

var body = languageId == 0
    ? entity.Description
    : await _localizationService.GetLocalizedAsync(entity, e => e.Description, languageId, false);
var stripped = Regex.Replace(body ?? string.Empty, "<.*?>", string.Empty);
if (string.IsNullOrWhiteSpace(stripped))
    // do not call AI meta generation; prompt user to add text content
    return;

Type guard

static bool HasTextContent(string html)
    => !string.IsNullOrWhiteSpace(Regex.Replace(html ?? string.Empty, "<.*?>", string.Empty));

Try / catch

try { await _aiService.CreateMetaTagsAsync(entity, languageId); }
catch (NopException ex) { /* body missing/empty — prompt user to add description text */ }

Prevention

When it happens

Trigger: AI meta/product generation where the entity's body/description is empty, or consists solely of markup/img tags that become empty after tag-stripping (e.g. '<img src=...>' with no text).

Common situations: A product with FullDescription containing only an image; a topic/blog post with empty body; localized description empty in the target language; description that is whitespace-only.

Related errors


AI-assisted analysis of nopSolutions/nopCommerce@64bdf2ff08 (2026-08-13). Data as JSON: /api/errors/8beb2464bc13c1e7. Report an issue: GitHub.

Appendix: source

Thrown at src/Libraries/Nop.Services/ArtificialIntelligence/ArtificialIntelligenceService.cs:281

    /// <param name="textRequiredLocale">Locale for raising an exception about the title field required</param>
    /// <param name="titleRequiredLocale">Locale for raising an exception about the text field required</param>
    /// <param name="title">Title for validate</param>
    /// <param name="text">Text for validate</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the validated title and text
    /// </returns>
    public virtual async Task<(string title, string text)> ValidateTitleAndTextAsync(string languageName,
        string textRequiredLocale, string titleRequiredLocale, string title, string text)
    {
        if (string.IsNullOrEmpty(title))
            throw new NopException(string.Format(await _localizationService.GetResourceAsync(titleRequiredLocale), languageName));

        if (!string.IsNullOrEmpty(text))
            text = Regex.Replace(text, "<.*?>", string.Empty);

        if (string.IsNullOrEmpty(text))
            throw new NopException(string.Format(await _localizationService.GetResourceAsync(textRequiredLocale), languageName));

        return (title, text);
    }

    /// <summary>
    /// Create product description by artificial intelligence
    /// </summary>
    /// <param name="productName">Product name</param>
    /// <param name="keywords">Features and keywords</param>
    /// <param name="toneOfVoice">Tone of voice</param>
    /// <param name="instruction">Special instruction</param>
    /// <param name="customToneOfVoice">Custom tone of voice (applicable only for ToneOfVoiceType.Custom)</param>
    /// <param name="languageId">The language identifier</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the generated product description
    /// </returns>
    public virtual async Task<string> CreateProductDescriptionAsync(string productName, string keywords, ToneOfVoiceType toneOfVoice, string instruction, string customToneOfVoice = null, int languageId = 0)

View on GitHub (pinned to 64bdf2ff08)