{"record":{"id":"c7b3acf05223e788","repo":"Orbmu2k/nvidiaProfileInspector","slug":"base-profile-cannot-be-deleted","errorCode":null,"errorMessage":"Base profile cannot be deleted.","messagePattern":"Base profile cannot be deleted\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsService.cs","lineNumber":142,"sourceCode":"                }\r\n            }\r\n            finally\r\n            {\r\n                if (File.Exists(tmpFileName))\r\n                    File.Delete(tmpFileName);\r\n            }\r\n        }\r\n\r\n        public void DeleteProfile(string profileName)\r\n        {\r\n            DrsSession((hSession) =>\r\n            {\r\n                var hProfile = GetProfileHandle(hSession, profileName);\r\n\r\n                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","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsService.cs#L124-L160","documentation":"InvalidOperationException(\"Base profile cannot be deleted.\") is a library-level guard in DeleteProfile: it resolves the handle of the profile named 'Profile' (the driver's built-in Base Profile) and refuses to delete it, since the base profile is the global fallback that must always exist.","triggerScenarios":"Calling DeleteProfile with the base profile's name (or a name that resolves to the same handle as GetProfileHandle(hSession, null)) triggers this at DrsSettingsService.cs:142 before any destructive DRS call is made.","commonSituations":"User selects 'Base Profile' in a UI and clicks delete; automated scripts iterating all profiles including the base one; importing a profile list that includes a 'Profile' entry and then deleting by that name.","solutions":["Skip profiles whose handle equals GetProfileHandle(hSession, null) before calling DeleteProfile","Filter out the base profile from any user-facing deletion list","Catch InvalidOperationException and show a 'cannot delete base profile' message instead of crashing","Delete only profiles explicitly created by the user/import"],"exampleFix":"// before\nsettingsService.DeleteProfile(profileName);\n// after\nif (!string.Equals(profileName, \"Profile\", StringComparison.OrdinalIgnoreCase))\n    settingsService.DeleteProfile(profileName);","handlingStrategy":"validation","validationCode":"static bool IsBaseProfile(string name) =>\n    string.Equals(name, \"Profile\", StringComparison.OrdinalIgnoreCase);\n\nif (IsBaseProfile(profileName)) throw new InvalidOperationException(\"Refusing to delete base profile\");","typeGuard":null,"tryCatchPattern":"try\n{\n    settingsService.DeleteProfile(profileName);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Base profile\"))\n{\n    MessageBox.Show(\"The Base Profile cannot be deleted.\");\n}","preventionTips":["Exclude the base profile from deletion lists in UI and scripts","Compare against GetProfileHandle(hSession, null) rather than hardcoding the name when possible","Never iterate-and-delete all profiles without filtering built-ins","Catch InvalidOperationException from DeleteProfile and surface a clear message"],"tags":["drs","profile-deletion","validation","driver-settings"],"backgroundTag":"invalid-argument-value","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"}