Orbmu2k/nvidiaProfileInspector · warning · NvapiException
DRS_DestroySession
Error message
DRS_DestroySession
What it means
NvapiException("DRS_DestroySession", status) is thrown from the finally block of NonGlobalDrsSession when DRS_DestroySession returns non-OK while cleaning up the per-operation session. Because it is thrown from finally, it can mask an exception thrown by the wrapped action.
Solutions
- Inspect any inner/original exception — the destroy failure is often secondary to the real error
- Ensure all handles derived from the session (profiles, applications) were released before destroy
- Avoid sharing session handles across threads; NonGlobalDrsSession sessions are not thread-safe for concurrent use
- Update the NVIDIA driver if destroy consistently fails
- Treat destroy failures as non-fatal where possible by wrapping cleanup in its own try-catch
Example fix
// before
finally
{
var nvRes = nvw.Instance.DRS_DestroySession(hSession);
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_DestroySession", nvRes);
}
// after
finally
{
var nvRes = nvw.Instance.DRS_DestroySession(hSession);
if (nvRes != NvAPI_Status.NVAPI_OK)
Log.Warn($"DRS_DestroySession failed: {nvRes}"); // don't mask action exceptions
} Defensive patterns
Strategy: try-catch
Try / catch
try
{
NonGlobalDrsSession(h => DoWork(h));
}
catch (NvapiException ex)
{
// Inspect ex — destroy failures in finally can mask the real error
Log.Error($"DRS operation failed: {ex.Message} {ex.Status}");
} Prevention
- Release all handles derived from the session before it is destroyed
- Don't use a session from multiple threads concurrently
- Treat destroy-status failures as secondary; find the root cause in the action's exception
- Log destroy failures instead of rethrowing from finally to avoid masking
When it happens
Trigger: Any scoped DRS operation (NonGlobalDrsSession callers) where the action completes or throws, then nvw.Instance.DRS_DestroySession(hSession) returns non-NVAPI_OK at DrsSessionScope.cs:86.
Common situations: Driver API state corrupted earlier in the operation (the real failure being masked); session already invalid because an earlier call failed; driver crash/reset mid-operation; rapid concurrent session teardown on the same driver state.
Related errors
- NvapiAddApplicationException(appName)
- DRS_CreateSession
- DRS_LoadSettings
- DRS_DeleteProfile
- DRS_RestoreAllDefaults
AI-assisted analysis of Orbmu2k/nvidiaProfileInspector@2f50c388b3 (2026-09-15).
Data as JSON: /api/errors/114238f172cee364.
Report an issue: GitHub.
Appendix: source
Thrown at nvidiaProfileInspector/Common/DrsSessionScope.cs:86
if (csRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_CreateSession", csRes);
try
{
if (!preventLoadSettings)
{
var nvRes = nvw.Instance.DRS_LoadSettings(hSession);
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_LoadSettings", nvRes);
}
return action(hSession);
}
finally
{
var nvRes = nvw.Instance.DRS_DestroySession(hSession);
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_DestroySession", nvRes);
}
}
}
}
View on GitHub (pinned to 2f50c388b3)