OrchardCMS/OrchardCore · error · ArgumentException

The values for and must not be the same.

Error message

The values for ${nameof(srcPath)} and ${nameof(dstPath)} must not be the same.

What it means

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.

Solutions

  1. Compare srcPath and dstPath before calling and skip the operation or return early when they are equal.
  2. Ensure the destination path differs (different directory or file name) before invoking CopyFileAsync.
  3. If the intent is a move/rename, only call MoveFileAsync when the target path is different.

Example fix

// before
await fileStore.CopyFileAsync(path, newPath); // newPath may equal path

// after
if (!string.Equals(path, newPath, StringComparison.Ordinal))
{
    await fileStore.CopyFileAsync(path, newPath);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.Equals(srcPath, dstPath, StringComparison.Ordinal))
{
    // skip copy or report a no-op
    return;
}

Prevention

When it happens

Trigger: Calling CopyFileAsync(srcPath, dstPath) with srcPath == dstPath (case-sensitive string comparison); also via MoveFileAsync when the destination equals the source.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/4f8627fa7d3a485f. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs:198

            var response = await _amazonS3Client.DeleteObjectsAsync(deleteObjectsRequest);
            return response.IsSuccessful();
        }

        return listObjectsResponse.IsSuccessful();
    }

    public async Task MoveFileAsync(string oldPath, string newPath)
    {
        await CopyFileAsync(oldPath, newPath);
        await TryDeleteFileAsync(oldPath);
    }

    public async Task CopyFileAsync(string srcPath, string dstPath)
    {
        if (srcPath == dstPath)
        {
            throw new ArgumentException($"The values for {nameof(srcPath)} and {nameof(dstPath)} must not be the same.");
        }

        try
        {
            await _amazonS3Client.GetObjectMetadataAsync(new GetObjectMetadataRequest
            {
                BucketName = _options.BucketName,
                Key = this.Combine(_basePrefix, srcPath),
            });
        }
        catch (AmazonS3Exception ex) when (ex.StatusCode == HttpStatusCode.NotFound)
        {
            throw new FileStoreException($"Cannot copy file '{srcPath}' because it does not exist.");
        }
        catch (AmazonS3Exception ex)
        {
            throw new FileStoreException($"Error accessing file '{srcPath}': {ex.Message}", ex);
        }

View on GitHub (pinned to 4306c0717f)