{"record":{"id":"63d38612e437b7f2","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-setsetting","errorCode":null,"errorMessage":"DRS_SetSetting","messagePattern":"DRS_SetSetting","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":121,"sourceCode":"\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,\n                settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION,\n                currentValue = new NVDRS_SETTING_UNION()\n                {\n                    dwordValue = dwordValue,\n                },\n            };\n\n            var ssRes = nvw.Instance.DRS_SetSetting(hSession, hProfile, ref newSetting);\n            if (ssRes != NvAPI_Status.NVAPI_OK)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L103-L139","documentation":"NvapiException thrown when DRS_SetSetting rejects a caller-built NVDRS_SETTING struct passed to StoreSetting. Because the caller constructs the NVDRS_SETTING here, the most common causes are a wrong/zero version field, an unknown or unsupported settingId, a settingType inconsistent with the union value written (e.g. DWORD type with a string value), or an invalid session/profile handle.","triggerScenarios":"Passing an NVDRS_SETTING whose version is not NVDRS_SETTING_VER, a settingId that this driver does not support (NVAPI_INVALID_ARGUMENT / NVAPI_SETTING_NOT_FOUND semantics), settingType not matching the populated currentValue union member, a string setting longer than NVAPI settings string limits, or a bad hSession/hProfile.","commonSituations":"Hand-rolling NVDRS_SETTING structs and forgetting the version field, applying settings from an exported .nip file to a newer driver where the setting was removed, mixing DWORD/QWORD/string union members incorrectly, or writing to a handle captured before the driver settings store was reloaded.","solutions":["Verify newSetting.version == NVDRS_SETTING_VER is set on the struct before calling StoreSetting.","Confirm settingType matches the union member populated in currentValue (DWORD vs QWORD vs WSTRING vs BINARY).","Validate the settingId exists for this driver via DRS_GetSettingInfo / the settings meta service before writing.","Check ex.Status: NVAPI_INVALID_ARGUMENT => struct/enum problem; NVAPI_ERROR => driver-side, retry after reloading the store.","Use the typed helpers (StoreDwordValue/StoreStringValue/etc.) instead of raw StoreSetting so version and type are always consistent."],"exampleFix":"// before\nvar s = new NVDRS_SETTING { settingId = id, settingType = NVDRS_DWORD_TYPE }; // version missing\nservice.StoreSetting(hSession, hProfile, s);\n// after\nvar s = new NVDRS_SETTING {\n    version = nvw.NVDRS_SETTING_VER,\n    settingId = id,\n    settingType = NVDRS_DWORD_TYPE,\n    currentValue = new NVDRS_SETTING_UNION { dwordValue = value }\n};\nservice.StoreSetting(hSession, hProfile, s);","handlingStrategy":"validation","validationCode":"if (newSetting.version == 0)\n    throw new ArgumentException(\"NVDRS_SETTING.version must be set (NVDRS_SETTING_VER)\");\nif (!Enum.IsDefined(typeof(NVDRS_SETTING_TYPE), newSetting.settingType))\n    throw new ArgumentException(\"Unknown settingType\");","typeGuard":"static bool IsWritableSetting(NVDRS_SETTING s) =>\n    s.version != 0 && s.settingId != 0 &&\n    (s.settingType == NVDRS_DWORD_TYPE ? s.currentValue.dwordValue != 0 : true);","tryCatchPattern":"try { StoreSetting(hSession, hProfile, setting); }\ncatch (NvapiException ex)\n{\n    log.Error($\"SetSetting failed for 0x{setting.settingId:X}: {ex.Status}\");\n    if (ex.Status != NvAPI_Status.NVAPI_INVALID_ARGUMENT) throw;\n}","preventionTips":["Prefer the typed helpers (StoreDwordValue etc.) over raw StoreSetting so version/type stay consistent.","Ensure settingType matches the populated currentValue union member.","Validate settingId against the driver's setting database before writing.","Set version = NVDRS_SETTING_VER on every struct.","Test writes against the oldest driver version you must support."],"tags":["nvapi","drs","settings-write","struct-marshaling","windows"],"backgroundTag":"schema-validation-failed","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"}