memstechtips/Winhance · error · InsufficientDiskSpaceException

Insufficient disk space on {driveName} for {operationName}.

Error message

Insufficient disk space on {driveName} for {operationName}. Required: {requiredGB:F2} GB, Available: {availableGB:F2} GB

What it means

InsufficientDiskSpaceException (a custom Winhance exception) thrown by DismProcessRunner.CheckDiskSpaceAsync when DriveInfo.AvailableFreeSpace on the target drive's root is less than requiredBytes. The exception carries DriveName, RequiredGB, AvailableGB, and OperationName so callers can show a precise, actionable message.

Source

Thrown at src/Winhance.Infrastructure/Features/Common/Services/DismProcessRunner.cs:98

            var drive = new DriveInfo(_fileSystemService.GetPathRoot(path)!);
            var availableBytes = drive.AvailableFreeSpace;

            var availableGB = availableBytes / (1024.0 * 1024 * 1024);
            var requiredGB = requiredBytes / (1024.0 * 1024 * 1024);

            _logService.LogInformation(
                $"Disk space check for {operationName}: " +
                $"Required: {requiredGB:F2} GB, Available: {availableGB:F2} GB on {drive.Name}"
            );

            if (availableBytes < requiredBytes)
            {
                _logService.LogError(
                    $"Insufficient disk space for {operationName}. " +
                    $"Required: {requiredGB:F2} GB, Available: {availableGB:F2} GB"
                );

                throw new InsufficientDiskSpaceException(
                    drive.Name,
                    requiredGB,
                    availableGB,
                    operationName
                );
            }

            return true;
        }
        catch (InsufficientDiskSpaceException)
        {
            throw;
        }
        catch (Exception ex)
        {
            _logService.LogWarning($"Could not check disk space: {ex.Message}");
            return true;
        }

View on GitHub (pinned to f23d554eb2)

Solutions

  1. Free space on the named drive or choose an output path on a drive with more room, then retry.
  2. If the required estimate is conservative, lower the requiredBytes passed in for that operation (after confirming the real need).
  3. Check for disk quotas: AvailableFreeSpace reflects the user's quota, not total free — adjust the quota or run as a user without one.
  4. Clean up stale large files (old ISOs, exported WIMs, temp staging dirs) the app may have left behind.
  5. Run the operation on a different physical drive with adequate free space.

Example fix

// before: a single hard requirement
if (availableBytes < requiredBytes)
    throw new InsufficientDiskSpaceException(drive.Name, requiredGB, availableGB, operationName);

// after: warn-but-continue when the estimate has a safety margin, throw only on hard shortfall
var safetyFactor = 0.8; // caller may pass a 20% padded estimate
if (availableBytes < requiredBytes * safetyFactor)
    throw new InsufficientDiskSpaceException(drive.Name, requiredGB, availableGB, operationName);
if (availableBytes < requiredBytes)
    _logService.LogWarning($"Disk space below estimate for {operationName} but above safety floor; proceeding.");
Defensive patterns

Strategy: validation

Validate before calling

// Pre-check free space yourself with the same logic before the heavyweight op.
long AvailableBytes(string path)
{
    var root = System.IO.Path.GetPathRoot(path);
    return new System.IO.DriveInfo(root).AvailableFreeSpace;
}

Try / catch

catch (InsufficientDiskSpaceException ex)
{
    // ex has DriveName, RequiredGB, AvailableGB, OperationName — show a precise 'free N GB on drive X' prompt.
}

Prevention

When it happens

Trigger: CheckDiskSpaceAsync(path, requiredBytes, operationName) is called before a heavyweight operation (ISO creation, WIM export, image mount). GetPathRoot(path) resolves the drive; if AvailableFreeSpace < requiredBytes, the exception is thrown. OperationName like "ISO creation" is shown in the message.

Common situations: The output/temp drive is the system drive and is low on space. The user pointed output at a small USB/secondary partition. A previous large ISO/WIM filled the drive. The required-space estimate (a fixed GB constant) overestimates for the actual operation. Quotas reduce AvailableFreeSpace below total free space.

Related errors


AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13). Data as JSON: /api/errors/42351c39e2e9a861. Report an issue: GitHub.