{"record":{"id":"4ed29841a3b3ea9e","repo":"nopSolutions/nopCommerce","slug":"product-name-is-required","errorCode":null,"errorMessage":"Product name is required","messagePattern":"Product name is required","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Libraries/Nop.Services/Catalog/CopyProductService.cs","lineNumber":818,"sourceCode":"    /// <summary>\r\n    /// Create a copy of product with all depended data\r\n    /// </summary>\r\n    /// <param name=\"product\">The product to copy</param>\r\n    /// <param name=\"newName\">The name of product duplicate</param>\r\n    /// <param name=\"isPublished\">A value indicating whether the product duplicate should be published</param>\r\n    /// <param name=\"copyMultimedia\">A value indicating whether the product images and videos should be copied</param>\r\n    /// <param name=\"copyAssociatedProducts\">A value indicating whether the copy associated products</param>\r\n    /// <returns>\r\n    /// A task that represents the asynchronous operation\r\n    /// The task result contains the product copy\r\n    /// </returns>\r\n    public virtual async Task<Product> CopyProductAsync(Product product, string newName,\r\n        bool isPublished = true, bool copyMultimedia = true, bool copyAssociatedProducts = true)\r\n    {\r\n        ArgumentNullException.ThrowIfNull(product);\r\n\r\n        if (string.IsNullOrEmpty(newName))\r\n            throw new ArgumentException(\"Product name is required\");\r\n\r\n        var productCopy = await CopyBaseProductDataAsync(product, newName, isPublished);\r\n\r\n        //localization\r\n        await CopyLocalizationDataAsync(product, productCopy);\r\n\r\n        //copy product tags\r\n        foreach (var productTag in await _productTagService.GetAllProductTagsByProductIdAsync(product.Id))\r\n            await _productTagService.InsertProductProductTagMappingAsync(new ProductProductTagMapping { ProductTagId = productTag.Id, ProductId = productCopy.Id });\r\n\r\n        //copy product pictures\r\n        var originalNewPictureIdentifiers = await CopyProductPicturesAsync(product, newName, copyMultimedia, productCopy);\r\n\r\n        //copy product videos\r\n        await CopyProductVideosAsync(product, copyMultimedia, productCopy);\r\n\r\n        //quantity change history\r\n        await _productService.AddStockQuantityHistoryEntryAsync(productCopy, product.StockQuantity, product.StockQuantity, product.WarehouseId,\r","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/nopSolutions/nopCommerce/blob/64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2/src/Libraries/Nop.Services/Catalog/CopyProductService.cs#L800-L836","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure newName is a non-empty string before calling CopyProductAsync — validate it at the UI/form layer (required attribute on the input).","Guard at the call site: if (!string.IsNullOrWhiteSpace(newName)) await service.CopyProductAsync(product, newName.Trim()); else report a validation error to the user.","If copying programmatically, default newName to a generated value like $\"{product.Name} (copy)\" when the caller has no name."],"exampleFix":"// before\nvar copy = await _copyProductService.CopyProductAsync(product, request.NewName);\n\n// after\nif (string.IsNullOrWhiteSpace(request.NewName))\n    ModelState.AddModelError(nameof(request.NewName), \"Product name is required\");\nelse\n    var copy = await _copyProductService.CopyProductAsync(product, request.NewName.Trim());","handlingStrategy":"validation","validationCode":"if (product is null) throw new ArgumentNullException(nameof(product));\nif (string.IsNullOrWhiteSpace(newName))\n    throw new InvalidOperationException(\"Cannot copy: newName is empty.\");\nvar copy = await _copyProductService.CopyProductAsync(product, newName.Trim());","typeGuard":"static bool IsValidNewProductName(string name) => !string.IsNullOrWhiteSpace(name);","tryCatchPattern":null,"preventionTips":["Mark the newName form field [Required] at the API boundary.","Default to $\"{product.Name} (copy)\" when the caller has no explicit name.","Unit-test CopyProductAsync callers with null/empty newName to confirm validation upstream."],"tags":["catalog","product","validation","argument","copy"],"backgroundTag":null,"analyzedSha":"64bdf2ff08c8b39e65717bcf974fb43dc2ef68f2","analyzedAt":"2026-08-13T21:19:38.062Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}