OrchardCMS/OrchardCore · error · FileStoreException

Cannot move file ' ' to ' '.

Error message

Cannot move file '{oldPath}' to '{newPath}'.

What it means

Wrapped FileStoreException from FileSystemStore.MoveFileAsync: the underlying File.Move threw (I/O error, source missing, path too long, locked file). Pre-existing FileStoreExceptions such as a destination conflict are rethrown unchanged; this one wraps only unexpected filesystem-level failures during the move.

Solutions

  1. Inspect InnerException for the actual IO error.
  2. Retry the move; transient locks often clear.
  3. Serialize concurrent moves to the same destination with a lock or queue.

Example fix

// before
await store.MoveFileAsync(src, dst); // throws on transient lock
// after
for (var i = 0; i < 3; i++)
{
    try { await store.MoveFileAsync(src, dst); break; }
    catch (FileStoreException) when (i < 2) { await Task.Delay(200); }
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-validate both paths before the move
if (await store.GetFileInfoAsync(oldPath) is null) throw new InvalidOperationException("missing source");
if (await store.GetFileInfoAsync(newPath) is not null) throw new InvalidOperationException("destination taken");

Try / catch

try { await store.MoveFileAsync(oldPath, newPath); }
catch (FileStoreException ex)
{
    _logger.LogError(ex.InnerException, "Move {Old} -> {New} failed", oldPath, newPath);
    throw;
}

Prevention

When it happens

Trigger: File.Move failing due to the source being locked, cross-volume move denied, invalid mapped path, or destination created by a concurrent request between the check and the move.

Common situations: Antivirus locking the file on Windows; storage root on a network share with transient failures; race conditions where another request creates the destination after validation.

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/04a93af88d6ee2b8. Report an issue: GitHub.

Appendix: source

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

            var physicalNewPath = GetPhysicalPath(newPath);

            if (File.Exists(physicalNewPath) || Directory.Exists(physicalNewPath))
            {
                throw new FileStoreException($"Cannot move file because the new path '{newPath}' already exists.");
            }

            File.Move(physicalOldPath, physicalNewPath);

            return Task.CompletedTask;
        }
        catch (FileStoreException)
        {
            throw;
        }
        catch (Exception ex)
        {
            throw new FileStoreException($"Cannot move file '{oldPath}' to '{newPath}'.", ex);
        }
    }

    public Task CopyFileAsync(string srcPath, string dstPath)
    {
        try
        {
            var physicalSrcPath = GetPhysicalPath(srcPath);

            if (!File.Exists(physicalSrcPath))
            {
                throw new FileStoreException($"The file '{srcPath}' does not exist.");
            }

            var physicalDstPath = GetPhysicalPath(dstPath);

            if (File.Exists(physicalDstPath) || Directory.Exists(physicalDstPath))
            {

View on GitHub (pinned to 4306c0717f)