Orbmu2k/nvidiaProfileInspector · error · NvapiException

DRS_CreateProfile

Error message

DRS_CreateProfile

What it means

NvapiException thrown when DRS_CreateProfile fails to create a new driver-settings profile with the given name in the open DRS session. The struct version field is set correctly (NVDRS_PROFILE_VER) and the name is pre-validated as non-empty, so the failure usually comes from the NVAPI side: an invalid session handle, NVAPI_INVALID_ARGUMENT from a struct marshaling mismatch, or driver-level rejection of the profile creation.

Solutions

  1. Check the inner NvapiException.Status: NVAPI_API_NOT_INITIALIZED/NO_IMPLEMENTATION => fix driver; NVAPI_INVALID_ARGUMENT => check struct version/marshaling.
  2. Ensure CreateProfile is called inside a live DrsSessionScope with a valid hSession from DRS_CreateSession.
  3. Update (or, for regressions, roll back) the NVIDIA driver; struct version mismatches appear after driver upgrades.
  4. Close NVIDIA Control Panel / other DRS consumers and retry if the settings store appears locked.
  5. If the profile may already exist, look it up with GetProfileHandle first (DRS_FindProfileByName) instead of creating blindly.

Example fix

// before
var hProfile = service.CreateProfile(hSession, name);
// after
var hProfile = service.GetProfileHandle(hSession, name);
if (hProfile == IntPtr.Zero)
    hProfile = service.CreateProfile(hSession, name);
Defensive patterns

Strategy: validation

Validate before calling

if (string.IsNullOrEmpty(profileName))
    throw new ArgumentException("Profile name must be non-empty", nameof(profileName));
if (hSession == IntPtr.Zero)
    throw new InvalidOperationException("DRS session not created");

Type guard

static bool CanCreate(IntPtr hSession, string name) => hSession != IntPtr.Zero && !string.IsNullOrEmpty(name);

Try / catch

try { hProfile = CreateProfile(hSession, name); }
catch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_ERROR)
{
    // settings store possibly locked; close NVIDIA Control Panel and retry once
}

Prevention

When it happens

Trigger: Calling CreateProfile with a destroyed or never-created session handle, a driver that returns NVAPI_INVALID_ARGUMENT due to NVDRS_PROFILE struct layout/version mismatch (driver API change), NVAPI_ERROR generic driver failure while the driver settings store is locked or corrupted, or profile names containing characters the driver rejects.

Common situations: Importing/creating profiles during a driver installation or while NVIDIA Control Panel holds the settings store, running with a broken driver install, on very old/new drivers where the DRS struct version changed, or code that reused a session after DrsSessionScope disposed it.

Understand the failure class

Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.

Related errors


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

Appendix: source

Thrown at nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs:99

            return hProfile;
        }

        protected IntPtr CreateProfile(IntPtr hSession, string profileName)
        {
            if (string.IsNullOrEmpty(profileName))
                throw new ArgumentNullException("profileName");

            var hProfile = IntPtr.Zero;

            var newProfile = new NVDRS_PROFILE()
            {
                version = nvw.NVDRS_PROFILE_VER,
                profileName = profileName,
            };

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

            return hProfile;
        }


        protected NVDRS_PROFILE GetProfileInfo(IntPtr hSession, IntPtr hProfile)
        {
            var tmpProfile = new NVDRS_PROFILE();
            tmpProfile.version = nvw.NVDRS_PROFILE_VER;

            var gpRes = nvw.Instance.DRS_GetProfileInfo(hSession, hProfile, ref tmpProfile);
            if (gpRes != NvAPI_Status.NVAPI_OK)
                throw new NvapiException("DRS_GetProfileInfo", gpRes);

            return tmpProfile;
        }

        protected void StoreSetting(IntPtr hSession, IntPtr hProfile, NVDRS_SETTING newSetting)

View on GitHub (pinned to 2f50c388b3)