{"record":{"id":"ad5d54f19d21a8a5","repo":"memstechtips/Winhance","slug":"dism-failed-with-exit-code-exitcode","errorCode":null,"errorMessage":"DISM failed with exit code: {exitCode}","messagePattern":"DISM failed with exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimImageService.cs","lineNumber":189,"sourceCode":"\r\n            for (int i = 1; i <= imageCount; i++)\r\n            {\r\n                progress?.Report(new TaskProgressDetail\r\n                {\r\n                    StatusText = _localization.GetString(\"Progress_ConvertingEdition\", i.ToString(), imageCount.ToString()),\r\n                    TerminalOutput = currentInfo.EditionNames.Count >= i\r\n                        ? currentInfo.EditionNames[i - 1]\r\n                        : $\"Index {i}\"\r\n                });\r\n\r\n                var arguments = $\"/Export-Image /SourceImageFile:\\\"{sourceFile}\\\" /SourceIndex:{i} /DestinationImageFile:\\\"{targetFile}\\\" /Compress:{compressionType} /CheckIntegrity\";\r\n\r\n                _logService.LogInformation($\"Exporting index {i}: dism.exe {arguments}\");\r\n\r\n                var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\r\n                if (exitCode != 0)\r\n                {\r\n                    throw new Exception($\"DISM failed with exit code: {exitCode}\");\r\n                }\r\n            }\r\n\r\n            await Task.Delay(2000, cancellationToken).ConfigureAwait(false);\r\n\r\n            if (!_fileSystemService.FileExists(targetFile))\r\n            {\r\n                _logService.LogError($\"Target file not found: {targetFile}\");\r\n                return false;\r\n            }\r\n\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                StatusText = _localization.GetString(\"Progress_RemovingOldFile\"),\r\n                TerminalOutput = $\"Deleting {_fileSystemService.GetFileName(sourceFile)}\"\r\n            });\r\n\r\n            var deleted = false;\r","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/WimImageService.cs#L171-L207","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nvar (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"DISM failed with exit code: {exitCode}\");\n\n// after: name the operation and surface DISM output; partial-success indexes are reported\nvar (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(\"dism.exe\", arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"DISM /Export-Image failed for index {i} (exit {exitCode}). DISM output: {output}\");","handlingStrategy":"validation","validationCode":"// Validate the source index range and source WIM before the export loop.\nasync Task<bool> IsIndexValid(string sourceFile, int index)\n{\n    // use DismApi.DismGetImageInfo to get real ImageCount, then return index <= ImageCount.\n}","typeGuard":null,"tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"DISM failed with exit code\"))\n{\n    // Inspect the TerminalOutput for the DISM error code; if it is /CheckIntegrity corruption,\n    // retry without /CheckIntegrity or prompt the user for a different source WIM.\n}","preventionTips":["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."],"tags":["dism","external-process","wim","windows","media"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}