Orbmu2k/nvidiaProfileInspector · error · NvapiException
DRS_FindProfileByName
Error message
DRS_FindProfileByName
What it means
NvapiException wrapping a non-OK NVAPI status from the DRS_FindProfileByName call, which looks up an NVIDIA driver-settings profile by name in an open DRS session. The library deliberately swallows NVAPI_PROFILE_NOT_FOUND (returns IntPtr.Zero so callers can create the profile), so this exception means a different, unexpected NVAPI failure occurred: typically NVAPI_API_NOT_INITIALIZED / NVAPI_SESSION_NOT_FOUND (bad or closed session handle), NVAPI_INVALID_ARGUMENT, or NVAPI_EXECUTABLE_NOT_FOUND when the NVAPI DLL could not load on a machine without NVIDIA drivers.
Solutions
- Verify an NVIDIA GPU with current drivers is installed and nvapi.dll loads (the static constructor's SYS_GetDriverAndBranchVersion returning NVAPI_OK is a good pre-check).
- Ensure DRS_CreateSession succeeded and the handle is used only inside the DrsSessionScope lifetime; never cache hSession across scopes.
- Log the inner NvapiException.Status to distinguish NVAPI_API_NOT_INITIALIZED (driver problem) from NVAPI_INVALID_ARGUMENT (bad name/handle).
- Update GeForce/Studio drivers; very old drivers lack parts of the DRS API and return NVAPI_NO_IMPLEMENTATION.
- If the profile genuinely may not exist, rely on the IntPtr.Zero return path instead of treating the exception as 'not found'.
Example fix
// before
var hProfile = service.GetProfileHandle(hSession, profileName); // throws NvapiException
// after
try
{
var hProfile = service.GetProfileHandle(hSession, profileName);
}
catch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_API_NOT_INITIALIZED)
{
// NVIDIA driver unavailable - surface a friendly message or skip DRS work
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!NvapiDrsWrapper.Instance.SYS_GetDriverAndBranchVersion(ref ver, ref branch).Equals(NvAPI_Status.NVAPI_OK))
throw new InvalidOperationException("NVIDIA driver/NVAPI unavailable");
if (string.IsNullOrWhiteSpace(profileName))
throw new ArgumentException("profileName required", nameof(profileName)); Type guard
static bool HasValidSession(IntPtr hSession) => hSession != IntPtr.Zero;
Try / catch
try { handle = GetProfileHandle(hSession, name); }
catch (NvapiException ex)
{
if (ex.Status == NvAPI_Status.NVAPI_API_NOT_INITIALIZED)
ReportDriverUnavailable();
else
throw; // do not treat as 'profile not found'
} Prevention
- Pre-check NVAPI availability (SYS_GetDriverAndBranchVersion) before any DRS work.
- Treat only the IntPtr.Zero return as 'profile not found'; the exception means something else.
- Keep all DRS calls inside the DrsSessionScope using its handle.
- Log NvapiException.Status for diagnosis.
- Keep NVIDIA drivers current on machines running the tool.
When it happens
Trigger: Calling GetProfileHandle with a session handle that was never created (DRS_CreateSession failed or its status was ignored), a session already destroyed by DRS_DestroySession, an invalid (non-NUL-terminated or oversized) profileName StringBuilder, or running on a system where nvapi.dll is missing/stale so the P/Invoke returns NVAPI_API_NOT_INITIALIZED or NVAPI_NO_IMPLEMENTATION.
Common situations: Running the tool on a machine with only integrated/AMD graphics (no NVIDIA driver => nvapi.dll absent), a broken or very old NVIDIA driver install, a driver update mid-run invalidating the DRS session, or a code path that closed the DrsSessionScope before calling GetProfileHandle.
Related errors
- DRS_CreateProfile
- NvapiAddApplicationException(appName)
- DRS_CreateSession
- DRS_LoadSettings
- DRS_DestroySession
AI-assisted analysis of Orbmu2k/nvidiaProfileInspector@2f50c388b3 (2026-09-15).
Data as JSON: /api/errors/eee63c04d96abbfe.
Report an issue: GitHub.
Appendix: source
Thrown at nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs:79
if (string.IsNullOrEmpty(profileName))
{
var nvRes = nvw.Instance.DRS_GetCurrentGlobalProfile(hSession, ref hProfile);
if (hProfile == IntPtr.Zero)
throw new NvapiException("DRS_GetCurrentGlobalProfile", NvAPI_Status.NVAPI_PROFILE_NOT_FOUND);
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_GetCurrentGlobalProfile", nvRes);
}
else
{
var nvRes = nvw.Instance.DRS_FindProfileByName(hSession, new StringBuilder(profileName), ref hProfile);
if (nvRes == NvAPI_Status.NVAPI_PROFILE_NOT_FOUND)
return IntPtr.Zero;
if (nvRes != NvAPI_Status.NVAPI_OK)
throw new NvapiException("DRS_FindProfileByName", nvRes);
}
return hProfile;
}
protected IntPtr CreateProfile(IntPtr hSession, string profileName)
{
if (string.IsNullOrEmpty(profileName))
throw new ArgumentNullException("profileName");
var hProfile = IntPtr.Zero;
var newProfile = new NVDRS_PROFILE()
{
version = nvw.NVDRS_PROFILE_VER,
profileName = profileName,
};
var nvRes = nvw.Instance.DRS_CreateProfile(hSession, ref newProfile, ref hProfile);View on GitHub (pinned to 2f50c388b3)