Orbmu2k/nvidiaProfileInspector · error · NvapiException
DRS_SetSetting
Error message
DRS_SetSetting
What it means
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.
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.
Example fix
// before
var s = new NVDRS_SETTING { settingId = id, settingType = NVDRS_DWORD_TYPE }; // version missing
service.StoreSetting(hSession, hProfile, s);
// after
var s = new NVDRS_SETTING {
version = nvw.NVDRS_SETTING_VER,
settingId = id,
settingType = NVDRS_DWORD_TYPE,
currentValue = new NVDRS_SETTING_UNION { dwordValue = value }
};
service.StoreSetting(hSession, hProfile, s); Defensive patterns
Strategy: validation
Validate before calling
if (newSetting.version == 0)
throw new ArgumentException("NVDRS_SETTING.version must be set (NVDRS_SETTING_VER)");
if (!Enum.IsDefined(typeof(NVDRS_SETTING_TYPE), newSetting.settingType))
throw new ArgumentException("Unknown settingType"); Type guard
static bool IsWritableSetting(NVDRS_SETTING s) =>
s.version != 0 && s.settingId != 0 &&
(s.settingType == NVDRS_DWORD_TYPE ? s.currentValue.dwordValue != 0 : true); Try / catch
try { StoreSetting(hSession, hProfile, setting); }
catch (NvapiException ex)
{
log.Error($"SetSetting failed for 0x{setting.settingId:X}: {ex.Status}");
if (ex.Status != NvAPI_Status.NVAPI_INVALID_ARGUMENT) throw;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- DRS_FindProfileByName
- DRS_CreateProfile
- DRS_GetProfileInfo
- NvapiAddApplicationException(appName)
- DRS_CreateSession
AI-assisted analysis of Orbmu2k/nvidiaProfileInspector@2f50c388b3 (2026-09-15).
Data as JSON: /api/errors/63d38612e437b7f2.
Report an issue: GitHub.
Appendix: source
Thrown at nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs:121
protected NVDRS_PROFILE GetProfileInfo(IntPtr hSession, IntPtr hProfile)
{
var tmpProfile = new NVDRS_PROFILE();
tmpProfile.version = nvw.NVDRS_PROFILE_VER;
var gpRes = nvw.Instance.DRS_GetProfileInfo(hSession, hProfile, ref tmpProfile);
if (gpRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_GetProfileInfo", gpRes);
return tmpProfile;
}
protected void StoreSetting(IntPtr hSession, IntPtr hProfile, NVDRS_SETTING newSetting)
{
var ssRes = nvw.Instance.DRS_SetSetting(hSession, hProfile, ref newSetting);
if (ssRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_SetSetting", ssRes);
}
protected void StoreDwordValue(IntPtr hSession, IntPtr hProfile, uint settingId, uint dwordValue)
{
var newSetting = new NVDRS_SETTING()
{
version = nvw.NVDRS_SETTING_VER,
settingId = settingId,
settingType = NVDRS_SETTING_TYPE.NVDRS_DWORD_TYPE,
settingLocation = NVDRS_SETTING_LOCATION.NVDRS_CURRENT_PROFILE_LOCATION,
currentValue = new NVDRS_SETTING_UNION()
{
dwordValue = dwordValue,
},
};
var ssRes = nvw.Instance.DRS_SetSetting(hSession, hProfile, ref newSetting);
if (ssRes != NvAPI_Status.NVAPI_OK)View on GitHub (pinned to 2f50c388b3)