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

CopyFileAsync rejects a copy whose source and destination paths are equal, throwing ArgumentException. A copy onto itself is a no-op at best and a data hazard at worst, so the library fails fast before any Azure call.

Solutions

  1. Compare and skip the operation when srcPath == dstPath.
  2. Normalize paths (case, slashes) before comparing if paths come from different sources.
  3. Fix the caller logic that produces identical source and destination.

Example fix

// before
await _fileStore.CopyFileAsync(path, path);
// after
if (srcPath != dstPath)
{
    await _fileStore.CopyFileAsync(srcPath, dstPath);
}
Defensive patterns

Strategy: validation

Validate before calling

if (string.Equals(srcPath, dstPath, StringComparison.Ordinal))
{
    return; // nothing to copy
}
await _fileStore.CopyFileAsync(srcPath, dstPath);

Type guard

bool isRealCopy(string src, string dst) => !string.Equals(src, dst, StringComparison.Ordinal);

Try / catch

try
{
    await _fileStore.CopyFileAsync(srcPath, dstPath);
}
catch (ArgumentException ex)
{
    _logger.LogWarning(ex, "Source and destination must differ");
}

Prevention

When it happens

Trigger: Calling IFileStore.CopyFileAsync(path, path) with identical strings; also surfaces via MoveFileAsync when oldPath == newPath.

Common situations: Off-by-one or normalization bugs where both arguments derive from the same variable; UI passes the same folder/filename for source and target in rename dialogs.

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/3056c0a62dbd11ec. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AzureBlob/BlobFileStore.cs:585

        try
        {
            await CopyFileAsync(oldPath, newPath);
            await TryDeleteFileAsync(oldPath);
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot move file '{oldPath}' to '{newPath}'.", ex);
        }
    }

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

            var oldBlob = GetBlobReference(srcPath);
            var newBlob = GetBlobReference(dstPath);

            if (!await oldBlob.ExistsAsync())
            {
                throw new FileStoreException($"Cannot copy file '{srcPath}' because it does not exist.");
            }

            if (await newBlob.ExistsAsync())
            {
                throw new FileStoreException($"Cannot copy file '{srcPath}' because a file already exists in the new path '{dstPath}'.");
            }

            await newBlob.StartCopyFromUriAsync(oldBlob.Uri);

            await Task.Delay(250);

View on GitHub (pinned to 4306c0717f)