{"record":{"id":"1a1d307943c2958b","repo":"memstechtips/Winhance","slug":"oscdimg-exe-failed-with-exit-code-exitcode","errorCode":null,"errorMessage":"oscdimg.exe failed with exit code: {exitCode}","messagePattern":"oscdimg\\.exe failed with exit code: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Winhance.Infrastructure/Features/AdvancedTools/Services/IsoService.cs","lineNumber":333,"sourceCode":"                _fileSystemService.CreateDirectory(outputDir);\r\n\r\n            if (_fileSystemService.FileExists(outputPath))\r\n            {\r\n                _fileSystemService.DeleteFile(outputPath);\r\n                _logService.LogInformation(\"Removed existing ISO file\");\r\n            }\r\n\r\n            var arguments = $\"-m -o -u2 -udfver102 -bootdata:2#p0,e,b\\\"{etfsbootPath}\\\"#pEF,e,b\\\"{efisysPath}\\\" \\\"{workingDirectory}\\\" \\\"{outputPath}\\\"\";\r\n\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                TerminalOutput = \"Running oscdimg.exe...\\nThis may take several minutes...\"\r\n            });\r\n\r\n            var (exitCode, _) = await _dismProcessRunner.RunProcessWithProgressAsync(oscdimgPath, arguments, progress, cancellationToken).ConfigureAwait(false);\r\n            if (exitCode != 0)\r\n            {\r\n                throw new Exception($\"oscdimg.exe failed with exit code: {exitCode}\");\r\n            }\r\n\r\n            // Verify ISO was created\r\n            if (!_fileSystemService.FileExists(outputPath))\r\n            {\r\n                _logService.LogError(\"ISO file was not created\");\r\n                return false;\r\n            }\r\n\r\n            var isoFileSize = _fileSystemService.GetFileSize(outputPath);\r\n            _logService.LogInformation($\"ISO created successfully: {outputPath} ({isoFileSize:N0} bytes)\");\r\n\r\n            progress?.Report(new TaskProgressDetail\r\n            {\r\n                StatusText = _localization.GetString(\"Progress_IsoCreatedSuccess\"),\r\n                TerminalOutput = $\"Location: {outputPath}\\nSize: {isoFileSize / (1024 * 1024):F2} MB\"\r\n            });\r\n\r","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/memstechtips/Winhance/blob/f23d554eb2d6400b1827bcc46b91294ffa53fbc9/src/Winhance.Infrastructure/Features/AdvancedTools/Services/IsoService.cs#L315-L351","documentation":"oscdimg.exe (the Windows ADK / Deployment Tools ISO authoring tool) exited with a non-zero code while building the ISO. oscdimg is the actual tool invoked with -m -o -u2 -udfver102 and the dual bootdata segment; a non-zero exit means image authoring failed. The thrown Exception carries only the exit code — oscdimg's textual error was streamed to progress output, not captured in the message.","triggerScenarios":"RunProcessWithProgressAsync returned exitCode != 0 from oscdimg.exe. Common oscdimg failure codes: 1 = invalid argument/path, 2 = cannot open source directory, 5 = access denied, or non-zero from a source directory containing a file locked by another process. Also thrown if oscdimg is a stub/wrong version that exits non-zero.","commonSituations":"The working directory path contains characters oscdimg mishandles. A file inside the working directory is locked. The output path is on a read-only or full drive. oscdimg.exe present is from a mismatched/older ADK that does not support the dual-bootdata syntax. Antivirus blocks oscdimg writing the ISO.","solutions":["Read the TerminalOutput lines captured during the run (shown in progress) — oscdimg prints the human-readable reason immediately before exiting.","Run the same oscdimg command line manually in an elevated command prompt to see the exact error and exit code.","Free space and write permissions on the output drive; close any process holding files in the working directory.","Reinstall/repair ADK Deployment Tools so oscdimg.exe matches the Windows build, or switch to the lightweight Microsoft.OSCDIMG winget package.","Add the oscdimg exit code into the thrown message so failures are self-describing (see exampleFix)."],"exampleFix":"// before\nif (exitCode != 0)\n    throw new Exception($\"oscdimg.exe failed with exit code: {exitCode}\");\n\n// after: capture stderr/stdout so the exception carries oscdimg's own reason\nvar (exitCode, output) = await _dismProcessRunner.RunProcessWithProgressAsync(oscdimgPath, arguments, progress, cancellationToken).ConfigureAwait(false);\nif (exitCode != 0)\n    throw new Exception($\"oscdimg.exe failed with exit code {exitCode}. Output: {output}\");","handlingStrategy":"try-catch","validationCode":"// Verify oscdimg is present and the working tree is consistent before invoking it.\nbool CanRunOscdimg(string oscdimgPath, string workingDirectory)\n    => _fileSystemService.FileExists(oscdimgPath) && _fileSystemService.DirectoryExists(workingDirectory);","typeGuard":null,"tryCatchPattern":"catch (Exception ex) when (ex.Message.Contains(\"oscdimg.exe failed\"))\n{\n    // Parse the exit code from the message; surface the TerminalOutput lines captured during the run\n    // (oscdimg's own text) to the user. Offer to retry after freeing handles / freeing disk space.\n}","preventionTips":["Always surface oscdimg's stdout/stderr (captured in progress) alongside the exit code.","Free disk space and close handles in the working directory before running oscdimg.","Match the oscdimg.exe build to the Windows build (ADK or Microsoft.OSCDIMG winget package)."],"tags":["iso","external-process","oscdimg","windows","adk"],"backgroundTag":null,"analyzedSha":"f23d554eb2d6400b1827bcc46b91294ffa53fbc9","analyzedAt":"2026-08-13T17:55:20.922Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}