{"record":{"id":"c196e1c6ce671c6b","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-enumsettings","errorCode":null,"errorMessage":"DRS_EnumSettings","messagePattern":"DRS_EnumSettings","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":377,"sourceCode":"            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\n            if (decrypter != null)\n            {\n                var profile = GetProfileInfo(hSession, hProfile);\n                for (int i = 0; i < settingCount; i++)\n                {\n                    decrypter.DecryptSettingIfNeeded(profile.profileName, ref settings[i]);\n                }\n            }\n\n            return settings.ToList();\n        }\n\n        protected List<NVDRS_APPLICATION_V4> GetProfileApplications(IntPtr hSession, IntPtr hProfile)\n        {\n            uint appCount = 512;\n            var apps = new NVDRS_APPLICATION_V4[512];\n            apps[0].version = NvapiDrsWrapper.NVDRS_APPLICATION_VER_V4;","sourceCodeStart":359,"sourceCodeEnd":395,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L359-L395","documentation":"NvapiException wrapping the NVAPI status returned by DRS_EnumSettings when it is neither NVAPI_OK nor the benign NVAPI_END_ENUMERATION. DRS_EnumSettings enumerates the driver settings on a profile; a non-OK status means the enumeration call itself failed at the NVIDIA driver interface level. The exception is thrown by GetProfileSettings in DrsSettingsServiceBase before any per-setting decryption/processing.","triggerScenarios":"Calling GetProfileSettings with an invalid or already-closed hSession/hProfile handle; the profile handle was invalidated by a driver reload or DRS_DestroySession; an NVAPI call earlier in the flow failed silently (e.g. Initialize without admin rights on some driver versions); passing a session created without DRS_CreateSession returning OK.","commonSituations":"Reading settings right after the NVIDIA driver was updated (session/handle invalidation); using a profile handle obtained from a different session; running without sufficient privileges so DRS calls return NVAPI_ERROR/NVAPI_NO_IMPLEMENTATION; app running before NVAPI_Initialize succeeded.","solutions":["Check that the NvapiException.Status is not NVAPI_END_ENUMERATION/expected value and log the exact status to identify the failure","Ensure NVAPI_Initialize succeeded and DRS_CreateSession/DRS_OpenProfileSession returned NVAPI_OK before enumerating","Re-create the DRS session and re-open the profile after driver updates or process changes","Verify the app runs with the privileges NVAPI DRS requires (usually the same user, sometimes admin for system profile)","Call NvapiDrsWrapper.Initialize once at startup and check its result instead of assuming it succeeded"],"exampleFix":"// before\nvar settings = GetProfileSettings(hSession, hProfile);\n// after\ntry { var settings = GetProfileSettings(hSession, hProfile); }\ncatch (NvapiException ex) { Log.Warn($\"DRS_EnumSettings failed: {ex.Status}\"); settings = new List<NVDRS_SETTING>(); }","handlingStrategy":"try-catch","validationCode":"if (hSession == IntPtr.Zero || hProfile == IntPtr.Zero) throw new InvalidOperationException(\"DRS session/profile not open\");","typeGuard":null,"tryCatchPattern":"try { settings = GetProfileSettings(hSession, hProfile); }\ncatch (NvapiException ex) { Log.Warn($\"DRS_EnumSettings failed with {ex.Status}\"); settings = new List<NVDRS_SETTING>(); }","preventionTips":["Initialize NVAPI once and verify it returned NVAPI_OK","Reuse handles from a single DRS session; recreate after driver updates","Check each DRS call's status instead of assuming success","Log the wrapped NvapiException.Status for diagnosis"],"tags":["nvapi","driver-settings","native-interop"],"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"}