{"record":{"id":"39133ebbfb0e671b","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-createapplication","errorCode":null,"errorMessage":"DRS_CreateApplication","messagePattern":"DRS_CreateApplication","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":251,"sourceCode":"        }\n\n        protected void AddApplication(IntPtr hSession, IntPtr hProfile, string applicationName)\n        {\n            var newApp = new NVDRS_APPLICATION_V4()\n            {\n                version = nvw.NVDRS_APPLICATION_VER_V4,\n                appName = applicationName,\n            };\n\n            var caRes = nvw.Instance.DRS_CreateApplication(hSession, hProfile, ref newApp);\n\n            if (caRes == NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE)\n            {\n                if (MitigateNvapiAlreadyInUseBug(hSession, hProfile, newApp)) return;\n            }\n\n            if (caRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_CreateApplication\", caRes);\n\n        }\n\n        protected void AddApplication(IntPtr hSession, IntPtr hProfile, string applicationName, string fileInFolder)\n        {\n            var newApp = new NVDRS_APPLICATION_V4()\n            {\n                version = nvw.NVDRS_APPLICATION_VER_V4,\n                appName = applicationName,\n                fileInFolder = fileInFolder\n            };\n\n            var caRes = nvw.Instance.DRS_CreateApplication(hSession, hProfile, ref newApp);\n\n            if (caRes == NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE)\n            {\n                if (MitigateNvapiAlreadyInUseBug(hSession, hProfile, newApp)) return;\n            }","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L233-L269","documentation":"NvapiException thrown by AddApplication when DRS_CreateApplication returns a non-OK status other than NVAPI_EXECUTABLE_ALREADY_IN_USE (which is intercepted for bug mitigation). It means the driver refused to register the executable in the profile. The wrapped NvAPI_Status gives the exact reason.","triggerScenarios":"AddApplication calls DRS_CreateApplication with an NVDRS_APPLICATION_V4 and the driver returns a failure status — invalid appName format, missing path/filename fields, invalid profile handle, or the executable already registered in another profile.","commonSituations":"Adding an app whose name is not a plain executable filename; adding an app already attached to another profile; wrong NVDRS_APPLICATION version field; stale hProfile handle.","solutions":["Check the NvapiException Status; if NVAPI_EXECUTABLE_ALREADY_IN_USE, the library's MitigateNvapiAlreadyInUseBug path should handle it — verify it ran.","Ensure applicationName is a valid executable file name and fileInFolder points to its directory, matching NVDRS_APPLICATION field expectations.","Confirm the hProfile handle is valid and the profile still exists.","Delete the duplicate application registration from the other profile (DRS_DeleteApplicationEx) and retry."],"exampleFix":"// before\nif (caRes != NvAPI_Status.NVAPI_OK)\n    throw new NvapiException(\"DRS_CreateApplication\", caRes);\n// after\nif (caRes == NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_ON_PROFILE)\n    return; // already registered, nothing to do\nif (caRes != NvAPI_Status.NVAPI_OK)\n    throw new NvapiException(\"DRS_CreateApplication\", caRes);","handlingStrategy":"validation","validationCode":"if (string.IsNullOrWhiteSpace(applicationName) ||\n    applicationName.Contains(\"\\\\\") || applicationName.Contains(\"/\"))\n    throw new ArgumentException(\"applicationName must be a bare executable file name\");","typeGuard":null,"tryCatchPattern":"try { AddApplication(hSession, hProfile, appName, folder); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_IN_USE)\n{ /* already registered elsewhere - decide whether to remove and re-add */ }\ncatch (NvapiException ex)\n{ log.Error($\"DRS_CreateApplication failed: {ex.Status}\"); throw; }","preventionTips":["Pass only the executable filename, not a full path, as the application name.","Check whether the app is already attached to another profile before adding.","Use matching struct version (V4) for the driver in use.","Ensure the profile handle is valid before AddApplication."],"tags":["nvapi","driver-settings","profile","native-interop"],"backgroundTag":"file-already-exists","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"}