{"record":{"id":"f5975802cb85bf87","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-createprofile","errorCode":null,"errorMessage":"DRS_CreateProfile","messagePattern":"DRS_CreateProfile","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":99,"sourceCode":"            return hProfile;\n        }\n\n        protected IntPtr CreateProfile(IntPtr hSession, string profileName)\n        {\n            if (string.IsNullOrEmpty(profileName))\n                throw new ArgumentNullException(\"profileName\");\n\n            var hProfile = IntPtr.Zero;\n\n            var newProfile = new NVDRS_PROFILE()\n            {\n                version = nvw.NVDRS_PROFILE_VER,\n                profileName = profileName,\n            };\n\n            var nvRes = nvw.Instance.DRS_CreateProfile(hSession, ref newProfile, ref hProfile);\n            if (nvRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_CreateProfile\", nvRes);\n\n            return hProfile;\n        }\n\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)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L81-L117","documentation":"NvapiException thrown when DRS_CreateProfile fails to create a new driver-settings profile with the given name in the open DRS session. The struct version field is set correctly (NVDRS_PROFILE_VER) and the name is pre-validated as non-empty, so the failure usually comes from the NVAPI side: an invalid session handle, NVAPI_INVALID_ARGUMENT from a struct marshaling mismatch, or driver-level rejection of the profile creation.","triggerScenarios":"Calling CreateProfile with a destroyed or never-created session handle, a driver that returns NVAPI_INVALID_ARGUMENT due to NVDRS_PROFILE struct layout/version mismatch (driver API change), NVAPI_ERROR generic driver failure while the driver settings store is locked or corrupted, or profile names containing characters the driver rejects.","commonSituations":"Importing/creating profiles during a driver installation or while NVIDIA Control Panel holds the settings store, running with a broken driver install, on very old/new drivers where the DRS struct version changed, or code that reused a session after DrsSessionScope disposed it.","solutions":["Check the inner NvapiException.Status: NVAPI_API_NOT_INITIALIZED/NO_IMPLEMENTATION => fix driver; NVAPI_INVALID_ARGUMENT => check struct version/marshaling.","Ensure CreateProfile is called inside a live DrsSessionScope with a valid hSession from DRS_CreateSession.","Update (or, for regressions, roll back) the NVIDIA driver; struct version mismatches appear after driver upgrades.","Close NVIDIA Control Panel / other DRS consumers and retry if the settings store appears locked.","If the profile may already exist, look it up with GetProfileHandle first (DRS_FindProfileByName) instead of creating blindly."],"exampleFix":"// before\nvar hProfile = service.CreateProfile(hSession, name);\n// after\nvar hProfile = service.GetProfileHandle(hSession, name);\nif (hProfile == IntPtr.Zero)\n    hProfile = service.CreateProfile(hSession, name);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(profileName))\n    throw new ArgumentException(\"Profile name must be non-empty\", nameof(profileName));\nif (hSession == IntPtr.Zero)\n    throw new InvalidOperationException(\"DRS session not created\");","typeGuard":"static bool CanCreate(IntPtr hSession, string name) => hSession != IntPtr.Zero && !string.IsNullOrEmpty(name);","tryCatchPattern":"try { hProfile = CreateProfile(hSession, name); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_ERROR)\n{\n    // settings store possibly locked; close NVIDIA Control Panel and retry once\n}","preventionTips":["Always look up the profile first (GetProfileHandle) and create only when the handle is IntPtr.Zero.","Create profiles inside a live DrsSessionScope.","Avoid profile names with exotic characters the driver may reject.","Don't run concurrent DRS writers (Control Panel, GeForce Experience, other instances).","Check ex.Status to separate driver problems from argument problems."],"tags":["nvapi","drs","profile-creation","driver-settings","windows"],"backgroundTag":"api-request-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"}