{"record":{"id":"36ca8fa983236d31","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-getprofileinfo","errorCode":null,"errorMessage":"DRS_GetProfileInfo","messagePattern":"DRS_GetProfileInfo","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":112,"sourceCode":"                profileName = profileName,\n            };\n\n            var nvRes = nvw.Instance.DRS_CreateProfile(hSession, ref newProfile, ref hProfile);\n            if (nvRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_CreateProfile\", nvRes);\n\n            return hProfile;\n        }\n\n\n        protected NVDRS_PROFILE GetProfileInfo(IntPtr hSession, IntPtr hProfile)\n        {\n            var tmpProfile = new NVDRS_PROFILE();\n            tmpProfile.version = nvw.NVDRS_PROFILE_VER;\n\n            var gpRes = nvw.Instance.DRS_GetProfileInfo(hSession, hProfile, ref tmpProfile);\n            if (gpRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_GetProfileInfo\", gpRes);\n\n            return tmpProfile;\n        }\n\n        protected void StoreSetting(IntPtr hSession, IntPtr hProfile, NVDRS_SETTING newSetting)\n        {\n            var ssRes = nvw.Instance.DRS_SetSetting(hSession, hProfile, ref newSetting);\n            if (ssRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_SetSetting\", ssRes);\n        }\n\n        protected void StoreDwordValue(IntPtr hSession, IntPtr hProfile, uint settingId, uint dwordValue)\n        {\n            var newSetting = new NVDRS_SETTING()\n            {\n                version = nvw.NVDRS_SETTING_VER,\n                settingId = settingId,\n                settingType = NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE,","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L94-L130","documentation":"NvapiException thrown when DRS_GetProfileInfo fails to fill an NVDRS_PROFILE struct for an existing profile handle. The library initializes tmpProfile with the correct NVDRS_PROFILE_VER before the call, so failures indicate an invalid session or profile handle, a struct version mismatch with the installed driver, or a generic driver error while reading the profile store.","triggerScenarios":"Calling GetProfileInfo with a stale hProfile (profile deleted or session destroyed), a handle from a different DRS session than hSession, a driver whose expected NVDRS_PROFILE version differs from the compiled-in NVDRS_PROFILE_VER (NVAPI_INVALID_ARGUMENT), or a corrupted driver settings store.","commonSituations":"Holding profile handles across DrsSessionScope boundaries (e.g. after MitigateNvapiAlreadyInUseBug or enumeration), driver upgrade between enumeration and info read, running against an old driver after updating the app, or profiles deleted concurrently by NVIDIA Control Panel.","solutions":["Re-fetch the profile handle inside the same DrsSessionScope instead of caching hProfile across scopes.","Check ex.Status: NVAPI_INVALID_ARGUMENT usually means NVDRS_PROFILE version mismatch - update the NVAPI wrapper/driver.","Verify hSession and hProfile come from the same DRS_CreateSession session.","Update the NVIDIA driver or the application's NVAPI definitions so struct versions agree.","If the profile was deleted concurrently, re-enumerate profiles (EnumProfileHandles) and retry."],"exampleFix":"// before\nvar info = service.GetProfileInfo(hSession, cachedHandle); // stale handle\n// after\nvar handle = service.GetProfileHandle(hSession, profileName);\nif (handle != IntPtr.Zero)\n{\n    var info = service.GetProfileInfo(hSession, handle);\n}","handlingStrategy":"try-catch","validationCode":"if (hProfile == IntPtr.Zero || hSession == IntPtr.Zero)\n    throw new ArgumentException(\"Session and profile handles must be non-zero\");","typeGuard":"static bool HasValidHandles(IntPtr hSession, IntPtr hProfile) => hSession != IntPtr.Zero && hProfile != IntPtr.Zero;","tryCatchPattern":"try { info = GetProfileInfo(hSession, hProfile); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_INVALID_ARGUMENT)\n{\n    // struct version mismatch or stale handle: re-resolve handle inside current scope\n    var fresh = GetProfileHandle(hSession, profileName);\n    if (fresh != IntPtr.Zero) info = GetProfileInfo(hSession, fresh);\n}","preventionTips":["Never cache profile handles across DrsSessionScope lifetimes.","Always set the struct version (NVDRS_PROFILE_VER) - the library does this, so prefer its API.","Use handles and sessions from the same DRS_CreateSession call.","After driver updates, re-enumerate handles instead of reusing old ones.","Catch and inspect NvapiException.Status rather than assuming the handle was bad."],"tags":["nvapi","drs","profile-info","handle-lifetime","windows"],"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"}