{"record":{"id":"4f8627fa7d3a485f","repo":"OrchardCMS/OrchardCore","slug":"the-values-for-nameof-srcpath-and-nameof-dstpath-must-not-be","errorCode":null,"errorMessage":"The values for ${nameof(srcPath)} and ${nameof(dstPath)} must not be the same.","messagePattern":"The values for (.+?) and (.+?) must not be the same\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs","lineNumber":198,"sourceCode":"\n            var response = await _amazonS3Client.DeleteObjectsAsync(deleteObjectsRequest);\n            return response.IsSuccessful();\n        }\n\n        return listObjectsResponse.IsSuccessful();\n    }\n\n    public async Task MoveFileAsync(string oldPath, string newPath)\n    {\n        await CopyFileAsync(oldPath, newPath);\n        await TryDeleteFileAsync(oldPath);\n    }\n\n    public async Task CopyFileAsync(string srcPath, string dstPath)\n    {\n        if (srcPath == dstPath)\n        {\n            throw new ArgumentException($\"The values for {nameof(srcPath)} and {nameof(dstPath)} must not be the same.\");\n        }\n\n        try\n        {\n            await _amazonS3Client.GetObjectMetadataAsync(new GetObjectMetadataRequest\n            {\n                BucketName = _options.BucketName,\n                Key = this.Combine(_basePrefix, srcPath),\n            });\n        }\n        catch (AmazonS3Exception ex) when (ex.StatusCode == HttpStatusCode.NotFound)\n        {\n            throw new FileStoreException($\"Cannot copy file '{srcPath}' because it does not exist.\");\n        }\n        catch (AmazonS3Exception ex)\n        {\n            throw new FileStoreException($\"Error accessing file '{srcPath}': {ex.Message}\", ex);\n        }","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs#L180-L216","documentation":"AwsFileStorage.CopyFileAsync rejects calls where the source and destination paths are identical. Copying a file onto itself is a no-op that would corrupt the copy semantics (the existence check on the destination would always fail), so the method fails fast with ArgumentException before any S3 call is made.","triggerScenarios":"Calling CopyFileAsync(srcPath, dstPath) with srcPath == dstPath (case-sensitive string comparison); also via MoveFileAsync when the destination equals the source.","commonSituations":"Computing the destination path with a bug (e.g. same variable passed twice), user input where the rename/copy target was not changed, loop code copying files into the same folder without changing names.","solutions":["Compare srcPath and dstPath before calling and skip the operation or return early when they are equal.","Ensure the destination path differs (different directory or file name) before invoking CopyFileAsync.","If the intent is a move/rename, only call MoveFileAsync when the target path is different."],"exampleFix":"// before\nawait fileStore.CopyFileAsync(path, newPath); // newPath may equal path\n\n// after\nif (!string.Equals(path, newPath, StringComparison.Ordinal))\n{\n    await fileStore.CopyFileAsync(path, newPath);\n}","handlingStrategy":"validation","validationCode":"if (string.Equals(srcPath, dstPath, StringComparison.Ordinal))\n{\n    // skip copy or report a no-op\n    return;\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always derive dstPath from srcPath with an explicit change (different folder or filename).","Add a unit test asserting copy-to-self is guarded.","Normalize paths before comparing to avoid case/separator surprises."],"tags":["argument-validation","s3","file-storage"],"backgroundTag":"invalid-argument-value","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}