Orbmu2k/nvidiaProfileInspector · error · InvalidOperationException

Base profile cannot be deleted.

Error message

Base profile cannot be deleted.

What it means

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.

Solutions

  1. Skip profiles whose handle equals GetProfileHandle(hSession, null) before calling DeleteProfile
  2. Filter out the base profile from any user-facing deletion list
  3. Catch InvalidOperationException and show a 'cannot delete base profile' message instead of crashing
  4. Delete only profiles explicitly created by the user/import

Example fix

// before
settingsService.DeleteProfile(profileName);
// after
if (!string.Equals(profileName, "Profile", StringComparison.OrdinalIgnoreCase))
    settingsService.DeleteProfile(profileName);
Defensive patterns

Strategy: validation

Validate before calling

static bool IsBaseProfile(string name) =>
    string.Equals(name, "Profile", StringComparison.OrdinalIgnoreCase);

if (IsBaseProfile(profileName)) throw new InvalidOperationException("Refusing to delete base profile");

Try / catch

try
{
    settingsService.DeleteProfile(profileName);
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Base profile"))
{
    MessageBox.Show("The Base Profile cannot be deleted.");
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of Orbmu2k/nvidiaProfileInspector@2f50c388b3 (2026-09-15). Data as JSON: /api/errors/c7b3acf05223e788. Report an issue: GitHub.

Appendix: source

Thrown at nvidiaProfileInspector/Common/DrsSettingsService.cs:142

                }
            }
            finally
            {
                if (File.Exists(tmpFileName))
                    File.Delete(tmpFileName);
            }
        }

        public void DeleteProfile(string profileName)
        {
            DrsSession((hSession) =>
            {
                var hProfile = GetProfileHandle(hSession, profileName);

                var baseProfileHandle = GetProfileHandle(hSession, null);
                if (hProfile == baseProfileHandle)
                {
                    throw new InvalidOperationException("Base profile cannot be deleted.");
                }


                if (hProfile != IntPtr.Zero)
                {
                    // Try removing applications from profile before deleting, prevents possible orphans
                    var applications = GetProfileApplications(hSession, hProfile);
                    foreach (var app in applications)
                    {
                        DeleteApplication(hSession, hProfile, app);
                    }

                    var nvRes = nvw.Instance.DRS_DeleteProfile(hSession, hProfile);
                    if (nvRes != NvAPI_Status.NVAPI_OK)
                        throw new NvapiException("DRS_DeleteProfile", nvRes);

                    SaveSettings(hSession);
                }

View on GitHub (pinned to 2f50c388b3)