stride3d/stride · error · InvalidOperationException

Unable to create directory

Error message

Unable to create directory [{0}]

What it means

CreateDirectory wraps Directory.CreateDirectory and converts any OS failure (permissions, invalid characters, IO errors) into an InvalidOperationException with the offending path, keeping the original exception as InnerException.

Solutions

  1. Check/fix write permissions on the parent directory
  2. Ensure the path does not point to an existing file; delete or rename it
  3. Inspect the InnerException for the exact OS error
  4. Verify the URL resolves to a valid local path (base path set correctly)

Example fix

// before
provider.CreateDirectory(outputUrl);
// after
if (!provider.DirectoryExists(outputUrl))
{
    try { provider.CreateDirectory(outputUrl); }
    catch (InvalidOperationException ex) { logger.Error($"Cannot create {outputUrl}: {ex.InnerException?.Message}"); throw; }
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (File.Exists(localPath)) throw new IOException($"{localPath} exists and is a file");
// ensure parent is writable beforehand
new FileInfo(localPath).Directory?.Refresh();

Try / catch

try { provider.CreateDirectory(url); }
catch (InvalidOperationException ex) { Log(ex.InnerException ?? ex); throw; }

Prevention

When it happens

Trigger: Calling provider.CreateDirectory(url) where the underlying path cannot be created: no write permission on parent, path is actually an existing file, illegal characters, disk full, or network share unavailable.

Common situations: Creating output folders on read-only deployments, sandboxed environments without write access, or when the path collides with an existing file.

Understand the failure class

Background: mkdir permission denied (EACCES): failed to create directory errors explained — this error's family across 32 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/f0f0049d1b9a4733. Report an issue: GitHub.

Appendix: source

Thrown at sources/core/Stride.Core.IO/FileSystemProvider.cs:83

    }

    public override bool DirectoryExists(string url)
    {
        var path = ConvertUrlToFullPath(url);
        return Directory.Exists(path);
    }

    /// <inheritdoc/>
    public override void CreateDirectory(string url)
    {
        var path = ConvertUrlToFullPath(url);
        try
        {
            Directory.CreateDirectory(path);
        }
        catch (Exception ex)
        {
            throw new InvalidOperationException("Unable to create directory [{0}]".ToFormat(path), ex);
        }
    }

    /// <inheritdoc/>
    public override bool FileExists(string url)
    {
        return File.Exists(ConvertUrlToFullPath(url));
    }

    public override long FileSize(string url)
    {
        var fileInfo = new FileInfo(ConvertUrlToFullPath(url));
        return fileInfo.Length;
    }

    /// <inheritdoc/>
    public override void FileDelete(string url)
    {

View on GitHub (pinned to 96fad776d2)