{"record":{"id":"de8275ec0d715047","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-findapplicationbyname","errorCode":null,"errorMessage":"DRS_FindApplicationByName","messagePattern":"DRS_FindApplicationByName","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":417,"sourceCode":"            if (esRes == NvAPI_Status.NVAPI_END_ENUMERATION)\n                return new List<NVDRS_APPLICATION_V4>();\n\n            if (esRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_EnumApplications\", esRes);\n\n            return apps.ToList();\n        }\n\n        protected IntPtr FindApplicationByName(IntPtr hSession, string appName)\n        {\n            IntPtr hProfile = IntPtr.Zero;\n            NVDRS_APPLICATION_V4 app = new NVDRS_APPLICATION_V4();\n            app.version = NvapiDrsWrapper.NVDRS_APPLICATION_VER_V4;\n\n            var res = NvapiDrsWrapper.Instance.DRS_FindApplicationByName(hSession, new StringBuilder(appName), ref hProfile, ref app);\n\n            if (res != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_FindApplicationByName\", res);\n\n            return hProfile;\n        }\n\n        protected void SaveSettings(IntPtr hSession)\n        {\n            var nvRes = nvw.Instance.DRS_SaveSettings(hSession);\n            if (nvRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_SaveSettings\", nvRes);\n        }\n\n        protected void LoadSettingsFileEx(IntPtr hSession, string filename)\n        {\n            var nvRes = nvw.Instance.DRS_LoadSettingsFromFileEx(hSession, new StringBuilder(filename));\n            if (nvRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_LoadSettingsFromFileEx\", nvRes);\n        }\n","sourceCodeStart":399,"sourceCodeEnd":435,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L399-L435","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Treat not-found statuses as a miss: pre-check or catch NvapiException and return null/handle absence gracefully","Pass only the executable file name (e.g. \"game.exe\"), not the full path","Ensure the session handle is valid and NVAPI was initialized","Use DRS_CreateApplication or fall back to the default profile when the application lookup misses","Normalize the app name (trim, strip path, keep original casing for NVAPI) before calling"],"exampleFix":"// before\nvar hProfile = FindApplicationByName(hSession, path);\n// after\nstring appName = Path.GetFileName(path);\ntry { var hProfile = FindApplicationByName(hSession, appName); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND) { return null; }","handlingStrategy":"try-catch","validationCode":"if (string.IsNullOrWhiteSpace(appName) || appName.IndexOf(Path.DirectorySeparatorChar) >= 0) appName = Path.GetFileName(appName);","typeGuard":null,"tryCatchPattern":"try { return FindApplicationByName(hSession, appName); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND) { return IntPtr.Zero; }","preventionTips":["Pass only the executable file name, not a full path","Handle 'not found' as a normal miss, not an exceptional failure path","Confirm the session handle is valid before lookup","Normalize/trim the app name before calling NVAPI"],"tags":["nvapi","driver-settings","native-interop"],"backgroundTag":"resource-not-found","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"}