nopSolutions/nopCommerce · error · ArgumentException

Product name is required

Error message

Product name is required

What it means

Thrown by CopyProductAsync as an ArgumentException when the newName argument is null or empty. This is a precondition check on the public API that duplicates a product under a new display name. It signals a programming error in the caller, not a runtime/environment problem.

Source

Thrown at src/Libraries/Nop.Services/Catalog/CopyProductService.cs:818

    /// <summary>
    /// Create a copy of product with all depended data
    /// </summary>
    /// <param name="product">The product to copy</param>
    /// <param name="newName">The name of product duplicate</param>
    /// <param name="isPublished">A value indicating whether the product duplicate should be published</param>
    /// <param name="copyMultimedia">A value indicating whether the product images and videos should be copied</param>
    /// <param name="copyAssociatedProducts">A value indicating whether the copy associated products</param>
    /// <returns>
    /// A task that represents the asynchronous operation
    /// The task result contains the product copy
    /// </returns>
    public virtual async Task<Product> CopyProductAsync(Product product, string newName,
        bool isPublished = true, bool copyMultimedia = true, bool copyAssociatedProducts = true)
    {
        ArgumentNullException.ThrowIfNull(product);

        if (string.IsNullOrEmpty(newName))
            throw new ArgumentException("Product name is required");

        var productCopy = await CopyBaseProductDataAsync(product, newName, isPublished);

        //localization
        await CopyLocalizationDataAsync(product, productCopy);

        //copy product tags
        foreach (var productTag in await _productTagService.GetAllProductTagsByProductIdAsync(product.Id))
            await _productTagService.InsertProductProductTagMappingAsync(new ProductProductTagMapping { ProductTagId = productTag.Id, ProductId = productCopy.Id });

        //copy product pictures
        var originalNewPictureIdentifiers = await CopyProductPicturesAsync(product, newName, copyMultimedia, productCopy);

        //copy product videos
        await CopyProductVideosAsync(product, copyMultimedia, productCopy);

        //quantity change history
        await _productService.AddStockQuantityHistoryEntryAsync(productCopy, product.StockQuantity, product.StockQuantity, product.WarehouseId,

View on GitHub (pinned to 64bdf2ff08)

Solutions

  1. Ensure newName is a non-empty string before calling CopyProductAsync — validate it at the UI/form layer (required attribute on the input).
  2. Guard at the call site: if (!string.IsNullOrWhiteSpace(newName)) await service.CopyProductAsync(product, newName.Trim()); else report a validation error to the user.
  3. If copying programmatically, default newName to a generated value like $"{product.Name} (copy)" when the caller has no name.

Example fix

// before
var copy = await _copyProductService.CopyProductAsync(product, request.NewName);

// after
if (string.IsNullOrWhiteSpace(request.NewName))
    ModelState.AddModelError(nameof(request.NewName), "Product name is required");
else
    var copy = await _copyProductService.CopyProductAsync(product, request.NewName.Trim());
Defensive patterns

Strategy: validation

Validate before calling

if (product is null) throw new ArgumentNullException(nameof(product));
if (string.IsNullOrWhiteSpace(newName))
    throw new InvalidOperationException("Cannot copy: newName is empty.");
var copy = await _copyProductService.CopyProductAsync(product, newName.Trim());

Type guard

static bool IsValidNewProductName(string name) => !string.IsNullOrWhiteSpace(name);

Prevention

When it happens

Trigger: Calling await copyProductService.CopyProductAsync(product, null) or CopyProductAsync(product, "") (or a whitespace-only string, since the check uses IsNullOrEmpty not IsNullOrWhiteSpace). Passing through an unvalidated user input from a copy-product form where the name field was omitted.

Common situations: A custom admin controller or plugin that wires a 'Copy product' button but forgets to validate the posted Name field; importing products via a script that supplies an empty target name; integration code that passes a model.Name that was never bound.

Related errors


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