Orbmu2k/nvidiaProfileInspector · error · NvapiException

DRS_FindApplicationByName

Error message

DRS_FindApplicationByName

What it means

NvapiException wrapping any non-OK status from DRS_FindApplicationByName, used by FindApplicationByName to locate the profile that contains a given application name. Unlike the enumeration calls, NVAPI_OK is the only success path here, so a lookup miss (e.g. NVAPI_EXECUTABLE_NOT_FOUND / profile not present) also throws. Callers: fullMatchProfile and MitigateNvapiAlreadyInUseBug.

Solutions

  1. Treat not-found statuses as a miss: pre-check or catch NvapiException and return null/handle absence gracefully
  2. Pass only the executable file name (e.g. "game.exe"), not the full path
  3. Ensure the session handle is valid and NVAPI was initialized
  4. Use DRS_CreateApplication or fall back to the default profile when the application lookup misses
  5. Normalize the app name (trim, strip path, keep original casing for NVAPI) before calling

Example fix

// before
var hProfile = FindApplicationByName(hSession, path);
// after
string appName = Path.GetFileName(path);
try { var hProfile = FindApplicationByName(hSession, appName); }
catch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND) { return null; }
Defensive patterns

Strategy: try-catch

Validate before calling

if (string.IsNullOrWhiteSpace(appName) || appName.IndexOf(Path.DirectorySeparatorChar) >= 0) appName = Path.GetFileName(appName);

Try / catch

try { return FindApplicationByName(hSession, appName); }
catch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND) { return IntPtr.Zero; }

Prevention

When it happens

Trigger: Searching for an application name that is not attached to any profile; appName not a valid executable name (empty, wrong case handling expectations, includes path when the driver expects only the file name); invalid hSession; the caller treats 'not found' as an error path instead of a normal miss.

Common situations: Looking up a profile for a newly installed game before any profile entry exists; passing a full path ("C:\\...\\game.exe") instead of the executable name; the NVIDIA 'NVAPI already in use' mitigation probing for known executables that are absent.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs:417

            if (esRes == NvAPI_Status.NVAPI_END_ENUMERATION)
                return new List<NVDRS_APPLICATION_V4>();

            if (esRes != NvAPI_Status.NVAPI_OK)
                throw new NvapiException("DRS_EnumApplications", esRes);

            return apps.ToList();
        }

        protected IntPtr FindApplicationByName(IntPtr hSession, string appName)
        {
            IntPtr hProfile = IntPtr.Zero;
            NVDRS_APPLICATION_V4 app = new NVDRS_APPLICATION_V4();
            app.version = NvapiDrsWrapper.NVDRS_APPLICATION_VER_V4;

            var res = NvapiDrsWrapper.Instance.DRS_FindApplicationByName(hSession, new StringBuilder(appName), ref hProfile, ref app);

            if (res != NvAPI_Status.NVAPI_OK)
                throw new NvapiException("DRS_FindApplicationByName", res);

            return hProfile;
        }

        protected void SaveSettings(IntPtr hSession)
        {
            var nvRes = nvw.Instance.DRS_SaveSettings(hSession);
            if (nvRes != NvAPI_Status.NVAPI_OK)
                throw new NvapiException("DRS_SaveSettings", nvRes);
        }

        protected void LoadSettingsFileEx(IntPtr hSession, string filename)
        {
            var nvRes = nvw.Instance.DRS_LoadSettingsFromFileEx(hSession, new StringBuilder(filename));
            if (nvRes != NvAPI_Status.NVAPI_OK)
                throw new NvapiException("DRS_LoadSettingsFromFileEx", nvRes);
        }

View on GitHub (pinned to 2f50c388b3)