memstechtips/Winhance · error · Exception
DISM failed with exit code: {exitCode}
Error message
DISM failed with exit code: {exitCode} What it means
DISM was invoked as `dism.exe /Export-Image /SourceImageFile:... /SourceIndex:N /DestinationImageFile:... /Compress:... /CheckIntegrity` to split/export one index of a WIM, and DISM exited non-zero. The loop iterates image indexes; a failure on any index aborts the whole export. Plain Exception carries only the exit code.
Source
Thrown at src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimImageService.cs:189
for (int i = 1; i <= imageCount; i++)
{
progress?.Report(new TaskProgressDetail
{
StatusText = _localization.GetString("Progress_ConvertingEdition", i.ToString(), imageCount.ToString()),
TerminalOutput = currentInfo.EditionNames.Count >= i
? currentInfo.EditionNames[i - 1]
: $"Index {i}"
});
var arguments = $"/Export-Image /SourceImageFile:\"{sourceFile}\" /SourceIndex:{i} /DestinationImageFile:\"{targetFile}\" /Compress:{compressionType} /CheckIntegrity";
_logService.LogInformation($"Exporting index {i}: dism.exe {arguments}");
var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
{
throw new Exception($"DISM failed with exit code: {exitCode}");
}
}
await Task.Delay(2000, cancellationToken).ConfigureAwait(false);
if (!_fileSystemService.FileExists(targetFile))
{
_logService.LogError($"Target file not found: {targetFile}");
return false;
}
progress?.Report(new TaskProgressDetail
{
StatusText = _localization.GetString("Progress_RemovingOldFile"),
TerminalOutput = $"Deleting {_fileSystemService.GetFileName(sourceFile)}"
});
var deleted = false;
View on GitHub (pinned to f23d554eb2)
Solutions
- Run `DISM /Get-WimInfo /WimFile:"<source>"` to list the real indexes and confirm the requested index exists.
- Drop /CheckIntegrity to see if the failure is corruption vs. a path/space problem; if it still fails, the source WIM is damaged.
- Free space on the destination drive; Export-Image needs space comparable to the image size.
- Inspect the DISM progress output streamed to TerminalOutput for the specific DISM error code.
- Ensure no other DISM/WIM operation holds the source or destination file.
Example fix
// before
var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
throw new Exception($"DISM failed with exit code: {exitCode}");
// after: name the operation and surface DISM output; partial-success indexes are reported
var (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync("dism.exe", arguments, progress, cancellationToken).ConfigureAwait(false);
if (exitCode != 0)
throw new Exception($"DISM /Export-Image failed for index {i} (exit {exitCode}). DISM output: {output}"); Defensive patterns
Strategy: validation
Validate before calling
// Validate the source index range and source WIM before the export loop.
async Task<bool> IsIndexValid(string sourceFile, int index)
{
// use DismApi.DismGetImageInfo to get real ImageCount, then return index <= ImageCount.
} Try / catch
catch (Exception ex) when (ex.Message.Contains("DISM failed with exit code"))
{
// Inspect the TerminalOutput for the DISM error code; if it is /CheckIntegrity corruption,
// retry without /CheckIntegrity or prompt the user for a different source WIM.
} Prevention
- Enumerate real indexes with DISM /Get-WimInfo before exporting.
- Free destination disk space comparable to the image size.
- Avoid holding the source/destination WIM with another process during export.
When it happens
Trigger: ExportImageAsync loops over indexes 1..N calling DISM /Export-Image per index; RunProcessWithProgressAsync returns non-zero for one of them. DISM export-image fails on: source index does not exist, source WIM is corrupted (/CheckIntegrity fails), destination is not writable or out of space, the compression type is invalid for the image, or a concurrent DISM session holds the file.
Common situations: Source WIM was edited by another tool and its index table is stale. SourceIndex exceeds the real index count. Destination drive is full. The WIM is an ESD that does not support /Compress:recovery. Another Winhance DISM operation is running (DismSessionManager serializes native DISM but dism.exe exports are separate processes).
Related errors
- DISM Export-Driver failed with exit code: {exitCode}
- Boot file not found: {etfsbootPath}
- UEFI boot file not found: {efisysPath}
- oscdimg.exe failed with exit code: {exitCode}
- ADK installation failed with exit code: {exitCode}
AI-assisted analysis of memstechtips/Winhance@f23d554eb2 (2026-08-13).
Data as JSON: /api/errors/ad5d54f19d21a8a5.
Report an issue: GitHub.