OrchardCMS/OrchardCore · error · FileStoreException

Cannot copy file ' ' to ' '.

Error message

Cannot copy file '{srcPath}' to '{dstPath}'.

What it means

Wrapped FileStoreException from FileSystemStore.CopyFileAsync: File.Copy itself threw after both pre-flight checks passed (source disappeared, permission error, disk full, path issues). Deliberate rejections like a missing source or existing destination are rethrown as-is; this variant wraps unexpected I/O failures.

Solutions

  1. Read InnerException to identify the real IO failure.
  2. Fix write permissions on the destination directory.
  3. Retry with backoff, and serialize copies to the same destination.

Example fix

// before
await store.CopyFileAsync(src, dst); // transient lock
// after
try { await store.CopyFileAsync(src, dst); }
catch (FileStoreException ex) { _logger.LogError(ex.InnerException, "Copy failed"); throw; }
Defensive patterns

Strategy: try-catch

Validate before calling

if (await store.GetFileInfoAsync(srcPath) is null) throw new InvalidOperationException("missing source");
if (await store.GetFileInfoAsync(dstPath) is not null) throw new InvalidOperationException("destination taken");

Try / catch

try { await store.CopyFileAsync(srcPath, dstPath); }
catch (FileStoreException ex)
{
    _logger.LogError(ex.InnerException, "Copy {Src} -> {Dst} failed", srcPath, dstPath);
    throw;
}

Prevention

When it happens

Trigger: File.Copy failing due to a locked source or destination, insufficient permissions, invalid mapped path, or a destination created concurrently between the check and the copy.

Common situations: Media folder permissions wrong for the app identity; file locked by another handler; race with a concurrent request copying to the same destination.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.FileSystem/FileSystemStore.cs:303

            var physicalDstPath = GetPhysicalPath(dstPath);

            if (File.Exists(physicalDstPath) || Directory.Exists(physicalDstPath))
            {
                throw new FileStoreException($"Cannot copy file because the destination path '{dstPath}' already exists.");
            }

            File.Copy(GetPhysicalPath(srcPath), GetPhysicalPath(dstPath));

            return Task.CompletedTask;
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot copy file '{srcPath}' to '{dstPath}'.", ex);
        }
    }

    public Task<Stream> GetFileStreamAsync(string path)
    {
        try
        {
            var physicalPath = GetPhysicalPath(path);

            if (!File.Exists(physicalPath))
            {
                throw new FileStoreException($"Cannot get file stream because the file '{path}' does not exist.");
            }

            var stream = File.OpenRead(physicalPath);

            return Task.FromResult<Stream>(stream);
        }

View on GitHub (pinned to 4306c0717f)