{"record":{"id":"bfb6899ce7340016","repo":"beeradmoore/dlss-swapper","slug":"process-exit-code-was-process-exitcode","errorCode":null,"errorMessage":"Process exit code was {process.ExitCode}","messagePattern":"Process exit code was (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Helpers/DLSSSettingsManager.cs","lineNumber":44,"sourceCode":"            Verb = \"runas\",\n            UseShellExecute = true,\n            CreateNoWindow = true\n        };\n\n        try\n        {\n            using (var process = Process.Start(processInfo))\n            {\n                if (process is not null)\n                {\n                    process.WaitForExit();\n\n                    if (process.ExitCode == 0)\n                    {\n                        return true;\n                    }\n\n                    throw new Exception(\"Process exit code was {process.ExitCode}\");\n                }\n            }\n        }\n        catch (Exception err)\n        {\n            Logger.Error(err, $\"Could not command \\\"{processInfo.FileName} {processInfo.Arguments}\");\n        }\n\n        return false;\n    }\n\n    public bool SetShowDlssIndicator(int value)\n    {\n        return RunRegAdd(NGXCORE_REG_KEY, \"ShowDlssIndicator\", \"REG_DWORD\", value.ToString(CultureInfo.InvariantCulture));\n    }\n\n    public int GetShowDlssIndicator()\n    {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/beeradmoore/dlss-swapper/blob/ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb/src/Helpers/DLSSSettingsManager.cs#L26-L62","documentation":"DLSSSettingsManager.RunRegAdd shells out to an external process (reg add) to change DLSS registry settings and returns true only when the process exits with code 0. Any non-zero exit code triggers this exception, surfacing that the external command failed. Notably, the message uses a non-interpolated string, so the log always reads literally 'Process exit code was {process.ExitCode}' — a string-formatting bug that hides the actual code.","triggerScenarios":"Calling SetShowDlssIndicator, SetLogLevel, or SetLoggingWindow when the spawned reg add process exits non-zero: invalid registry value name/data, target key does not exist and reg add cannot create it, insufficient privileges to write HKLM, or the executable is missing/blocked so it fails to run correctly.","commonSituations":"Running without administrator rights while writing to a protected hive; antivirus or AppLocker blocking reg.exe; typos in value names after a DLSS SDK version change; the ExitCode being a specific reg.exe error (e.g. 1 = access denied / invalid parameters).","solutions":["Fix the message to actually interpolate the exit code: use $\"Process exit code was {process.ExitCode}\" so failures are diagnosable.","Re-run the operation elevated (as administrator) — HKLM writes usually require admin rights.","Run the same reg add command manually in a console to see reg.exe's real error output.","Verify the registry key path and value name/data passed by the Set* caller are valid for the installed DLSS version.","Check that antivirus/execution policies are not silently blocking reg.exe."],"exampleFix":"// before\nthrow new Exception(\"Process exit code was {process.ExitCode}\");\n// after\nthrow new Exception($\"Process exit code was {process.ExitCode} for: {processInfo.FileName} {processInfo.Arguments}\");\n","handlingStrategy":"try-catch","validationCode":"static bool CanWriteRegistry(string keyPath)\n{\n    try\n    {\n        using var k = Registry.LocalMachine.OpenSubKey(keyPath, writable: true);\n        return k != null;\n    }\n    catch (UnauthorizedAccessException) { return false; }\n    catch (SecurityException) { return false; }\n}","typeGuard":"static bool Succeeded(Process process) => process is { HasExited: true, ExitCode: 0 };","tryCatchPattern":"try\n{\n    DLSSSettingsManager.SetShowDlssIndicator(true);\n}\ncatch (Exception ex) when (ex.Message.StartsWith(\"Process exit code was\"))\n{\n    Logger.Warn(ex, \"reg add failed - run the app as administrator to change DLSS settings.\");\n}","preventionTips":["Require elevation (or use a manifest with requireAdministrator) when writing HKLM registry values.","Always interpolate variables in exception messages ($\"...\") so diagnostics are not lost.","Capture and log stderr/stdout of external processes, not just the exit code.","Validate registry key path/value names against the installed DLSS SDK version before invoking reg add."],"tags":["process","registry","dlss","string-formatting-bug"],"backgroundTag":"command-not-found","analyzedSha":"ab9b1e2d4bb04187c48fe58eeea06c2b0ea71fbb","analyzedAt":"2026-09-15T05:25:32.979Z","contentChangedAt":"2026-09-15T05:25:32.979Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}