{"record":{"id":"d8c14cbb61557d77","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-createsession","errorCode":null,"errorMessage":"DRS_CreateSession","messagePattern":"DRS_CreateSession","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"critical","filePath":"nvidiaProfileInspector/Common/DrsSessionScope.cs","lineNumber":33,"sourceCode":"\n\n        public static T DrsSession<T>(Func<IntPtr, T> action, bool forceNonGlobalSession = false, bool preventLoadSettings = false)\n        {\n            lock (_Sync)\n            {\n                if (!HoldSession || forceNonGlobalSession)\n                    return NonGlobalDrsSession<T>(action, preventLoadSettings);\n\n\n                if (GlobalSession == IntPtr.Zero)\n                {\n\n#pragma warning disable CS0420\n                    var csRes = nvw.Instance.DRS_CreateSession(ref GlobalSession);\n#pragma warning restore CS0420\n\n                    if (csRes != NvAPI_Status.NVAPI_OK)\n                        throw new NvapiException(\"DRS_CreateSession\", csRes);\n\n                    if (!preventLoadSettings)\n                    {\n                        var nvRes = nvw.Instance.DRS_LoadSettings(GlobalSession);\n                        if (nvRes != NvAPI_Status.NVAPI_OK)\n                            throw new NvapiException(\"DRS_LoadSettings\", nvRes);\n                    }\n                }\n            }\n\n            if (GlobalSession != IntPtr.Zero)\n            {\n                return action(GlobalSession);\n            }\n\n            throw new Exception(nameof(GlobalSession) + \" is Zero!\");\n        }\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSessionScope.cs#L15-L51","documentation":"NvapiException(\"DRS_CreateSession\", status) is thrown when the global DRS session cannot be created — the nvapi DRS_CreateSession call returned a status other than NVAPI_OK while initializing the shared GlobalSession. Without a session, no driver-settings operations can run.","triggerScenarios":"DrsSession's lazy global-session initialization calls nvw.Instance.DRS_CreateSession(ref GlobalSession); any non-NVAPI_OK result raises this at DrsSessionScope.cs:33. This runs on the first DRS operation in the process unless preventLoadSettings paths skip loading.","commonSituations":"NVIDIA driver not installed or nvapi.dll missing/incompatible; running on a system without an NVIDIA GPU; driver API initialization failure (Initialize earlier failed); corrupted driver install after an update.","solutions":["Confirm an NVIDIA GPU and current driver are installed and nvapi.dll loads (check driver version)","Ensure nvapi.Initialize() succeeded before any DRS call","Reinstall/update the NVIDIA display driver","Check that the process is not sandboxed in a way that blocks driver API access","Wrap DrsSession usage to catch NvapiException and surface the raw status code for diagnosis"],"exampleFix":"// before\nDrsSession(hSession => { /* ... */ });\n// after\ntry { DrsSession(hSession => { /* ... */ }); }\ncatch (NvapiException ex)\n{\n    if (!NvapiAvailable()) throw new FriendlyException(\"NVIDIA driver settings are unavailable.\", ex);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"static bool IsNvidiaDriverAvailable()\n{\n    try { nvw.Instance.Initialize(); return true; }\n    catch { return false; }\n}","typeGuard":"static bool CanUseDrs() => Environment.OSVersion.Platform == PlatformID.Win32NT && IsNvidiaDriverAvailable();","tryCatchPattern":"try\n{\n    DrsSession(h => { /* work */ });\n}\ncatch (NvapiException ex)\n{\n    throw new DriverUnavailableException(\"NVIDIA driver settings unavailable\", ex);\n}","preventionTips":["Verify an NVIDIA GPU and matching driver are installed before launching DRS features","Match process bitness to nvapi.dll (x64 vs x86)","Call nvapi.Initialize once and check it succeeded before any DRS call","Feature-detect at startup and disable DRS UI when the driver is absent"],"tags":["nvapi","drs","session","driver-settings"],"backgroundTag":"module-init-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"}