{"record":{"id":"f384d6c0789a52d0","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-enumprofiles","errorCode":null,"errorMessage":"DRS_EnumProfiles","messagePattern":"DRS_EnumProfiles","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":360,"sourceCode":"            var profileHandles = new List<IntPtr>();\n            var hProfile = IntPtr.Zero;\n            uint index = 0;\n\n            NvAPI_Status nvRes;\n\n            do\n            {\n                nvRes = nvw.Instance.DRS_EnumProfiles(hSession, index, ref hProfile);\n                if (nvRes == NvAPI_Status.NVAPI_OK)\n                {\n                    profileHandles.Add(hProfile);\n                }\n                index++;\n            }\n            while (nvRes == NvAPI_Status.NVAPI_OK);\n\n            if (nvRes != NvAPI_Status.NVAPI_END_ENUMERATION)\n                throw new NvapiException(\"DRS_EnumProfiles\", nvRes);\n\n            return profileHandles;\n        }\n\n        protected List<NVDRS_SETTING> GetProfileSettings(IntPtr hSession, IntPtr hProfile, uint expectedCount = 512)\n        {\n            uint settingCount = expectedCount > 0 ? expectedCount : 1;\n            var settings = new NVDRS_SETTING[settingCount];\n            settings[0].version = NvapiDrsWrapper.NVDRS_SETTING_VER;\n\n            var esRes = NvapiDrsWrapper.Instance.DRS_EnumSettings(hSession, hProfile, 0, ref settingCount, ref settings);\n\n            if (esRes == NvAPI_Status.NVAPI_END_ENUMERATION)\n                return new List<NVDRS_SETTING>();\n\n            if (esRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_EnumSettings\", esRes);\n","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L342-L378","documentation":"NvapiException thrown by EnumProfileHandles when the profile enumeration loop terminates with any status other than NVAPI_OK or the expected NVAPI_END_ENUMERATION. The do/while loop enumerates profiles until the driver signals completion; any other terminating status (invalid session, internal error) is thrown. It indicates enumeration failed mid-way rather than completing normally.","triggerScenarios":"The DRS_EnumProfiles loop ends with a status that is neither NVAPI_OK (continue) nor NVAPI_END_ENUMERATION (done) — typically NVAPI_INVALID_ARGUMENT from a bad hSession, NVAPI_HANDLE_INVALIDATED, or an internal NVAPI error mid-enumeration.","commonSituations":"Calling enumeration after DRS_DestroySession; driver settings store locked by another process (e.g. NVIDIA Control Panel); driver reinstall/update while enumerating; corrupted driver profile database.","solutions":["Check the wrapped NvAPI_Status to distinguish invalid-session from internal-error cases.","Re-create the DRS session via DRS_CreateSession and ensure it stays open for the whole enumeration.","Close other NVIDIA tools that may lock the settings store and retry.","Update or cleanly reinstall the GPU driver if corruption is suspected."],"exampleFix":"// before\nif (nvRes != NvAPI_Status.NVAPI_END_ENUMERATION)\n    throw new NvapiException(\"DRS_EnumProfiles\", nvRes);\n// after\nif (nvRes != NvAPI_Status.NVAPI_END_ENUMERATION)\n{\n    if (nvRes == NvAPI_Status.NVAPI_HANDLE_INVALIDATED)\n        throw new InvalidOperationException(\"DRS session was invalidated during profile enumeration\");\n    throw new NvapiException(\"DRS_EnumProfiles\", nvRes);\n}","handlingStrategy":"try-catch","validationCode":"if (hSession == IntPtr.Zero)\n    throw new InvalidOperationException(\"DRS session not created\");","typeGuard":null,"tryCatchPattern":"try { var handles = EnumProfileHandles(hSession); }\ncatch (NvapiException ex)\n{ log.Error($\"DRS_EnumProfiles ended with {ex.Status}\"); /* recreate session and retry */ }","preventionTips":["Keep the DRS session open for the entire enumeration loop.","Avoid destroying/recreating the session concurrently with enumeration.","Close other NVIDIA utilities that may lock the settings store.","Update the driver if enumeration fails persistently."],"tags":["nvapi","driver-settings","enumeration","gpu"],"backgroundTag":"api-error-response","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"}