{"record":{"id":"700cfd02a744941c","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-deleteprofile","errorCode":null,"errorMessage":"DRS_DeleteProfile","messagePattern":"DRS_DeleteProfile","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsService.cs","lineNumber":157,"sourceCode":"                var baseProfileHandle = GetProfileHandle(hSession, null);\r\n                if (hProfile == baseProfileHandle)\r\n                {\r\n                    throw new InvalidOperationException(\"Base profile cannot be deleted.\");\r\n                }\r\n\r\n\r\n                if (hProfile != IntPtr.Zero)\r\n                {\r\n                    // Try removing applications from profile before deleting, prevents possible orphans\r\n                    var applications = GetProfileApplications(hSession, hProfile);\r\n                    foreach (var app in applications)\r\n                    {\r\n                        DeleteApplication(hSession, hProfile, app);\r\n                    }\r\n\r\n                    var nvRes = nvw.Instance.DRS_DeleteProfile(hSession, hProfile);\r\n                    if (nvRes != NvAPI_Status.NVAPI_OK)\r\n                        throw new NvapiException(\"DRS_DeleteProfile\", nvRes);\r\n\r\n                    SaveSettings(hSession);\r\n                }\r\n            });\r\n\r\n        }\r\n\r\n        public string GetProfileNameByExeName(string appName)\r\n        {\r\n            string profileName = string.Empty;\r\n\r\n            DrsSession((hSession) =>\r\n            {\r\n                var hProfile = FindApplicationByName(hSession, appName);\r\n                if (hProfile != IntPtr.Zero)\r\n                {\r\n                    var profile = GetProfileInfo(hSession, hProfile);\r\n\r","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsService.cs#L139-L175","documentation":"NvapiException(\"DRS_DeleteProfile\", status) is thrown when the driver API DRS_DeleteProfile call fails after the profile's applications were removed. The profile still exists on disk and the operation aborts before SaveSettings.","triggerScenarios":"DeleteProfile resolves the profile handle, deletes each of its applications, then calls nvw.Instance.DRS_DeleteProfile(hSession, hProfile); a non-NVAPI_OK result throws at DrsSettingsService.cs:157 inside the NonGlobalDrsSession callback.","commonSituations":"Profile already deleted by another process (handle stale); driver refuses to delete a protected/built-in profile; driver settings store locked or corrupted; permission issues.","solutions":["Re-fetch the profile list to confirm the profile still exists before deleting","Check the profile is not a driver-protected built-in (only base profile should be, but verify the name)","Close other applications using the driver settings store and retry","Run elevated if the settings store is permission-restricted","Catch NvapiException and log the status; refresh UI state since the profile may be partially modified"],"exampleFix":"// before\nsettingsService.DeleteProfile(profileName);\n// after\ntry { settingsService.DeleteProfile(profileName); }\ncatch (NvapiException ex)\n{\n    Log.Error($\"Failed to delete profile '{profileName}': {ex.Status}\");\n    RefreshProfileList();\n}","handlingStrategy":"try-catch","validationCode":"var profiles = settingsService.GetProfiles();\nif (!profiles.Any(p => string.Equals(p.Name, profileName, StringComparison.OrdinalIgnoreCase)))\n    return; // already gone — nothing to delete","typeGuard":null,"tryCatchPattern":"try\n{\n    settingsService.DeleteProfile(profileName);\n}\ncatch (NvapiException ex)\n{\n    Log.Error($\"DeleteProfile '{profileName}' failed: {ex.Status}\");\n    RefreshProfileList();\n}","preventionTips":["Confirm the profile still exists immediately before deleting","Avoid concurrent DRS writers (NVIDIA Control Panel, other tools)","Skip built-in/protected profiles before calling DeleteProfile","Refresh cached profile handles after any external driver-settings change"],"tags":["nvapi","drs","profile-deletion","driver-settings"],"backgroundTag":"api-error-response","analyzedSha":"2f50c388b3a4d661cade66b32746bec096d1eee1","analyzedAt":"2026-09-15T05:23:52.218Z","contentChangedAt":"2026-09-15T05:23:52.218Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}