{"record":{"id":"ebcc4b3ebbad0663","repo":"Orbmu2k/nvidiaProfileInspector","slug":"drs-deleteapplication","errorCode":null,"errorMessage":"DRS_DeleteApplication","messagePattern":"DRS_DeleteApplication","errorType":"exception","errorClass":"NvapiException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":337,"sourceCode":"            if (resCurrentProfile != NvAPI_Status.NVAPI_OK)\n                throw new ApplicationException($\"NVAPI Bug mitigation failed to add application '{pApplication.appName}' in current profile\");\n\n            var resOtherProfile = nvw.Instance.DRS_CreateApplication(hSession, otherProfile, ref appToRestore);\n            if (resOtherProfile != NvAPI_Status.NVAPI_OK)\n            {\n                var profile = GetProfileInfo(hSession, otherProfile);\n                throw new ApplicationException($\"NVAPI Bug mitigation failed to restore application '{appToRestore.appName}' in profile '{profile.profileName}'\");\n            }\n\n            return true;\n        }\n\n\n        protected void DeleteApplication(IntPtr hSession, IntPtr hProfile, NVDRS_APPLICATION_V4 application)\n        {\n            var caRes = nvw.Instance.DRS_DeleteApplicationEx(hSession, hProfile, ref application);\n            if (caRes != NvAPI_Status.NVAPI_OK)\n                throw new NvapiException(\"DRS_DeleteApplication\", caRes);\n        }\n\n        protected List<IntPtr> EnumProfileHandles(IntPtr hSession)\n        {\n            var profileHandles = new List<IntPtr>();\n            var hProfile = IntPtr.Zero;\n            uint index = 0;\n\n            NvAPI_Status nvRes;\n\n            do\n            {\n                nvRes = nvw.Instance.DRS_EnumProfiles(hSession, index, ref hProfile);\n                if (nvRes == NvAPI_Status.NVAPI_OK)\n                {\n                    profileHandles.Add(hProfile);\n                }\n                index++;","sourceCodeStart":319,"sourceCodeEnd":355,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L319-L355","documentation":"NvapiException thrown by DeleteApplication when DRS_DeleteApplicationEx returns a non-OK status. It means the driver refused to remove the executable registration from the profile. The wrapped NvAPI_Status gives the exact reason (app not found, invalid handle, etc.).","triggerScenarios":"DeleteApplication calls DRS_DeleteApplicationEx(hSession, hProfile, ref application) and the driver returns anything other than NVAPI_OK — application not registered in that profile, stale application struct/handle, invalid session, or internal NVAPI error.","commonSituations":"Deleting an app that was already removed (concurrent modification); passing an NVDRS_APPLICATION_V4 obtained from a different profile; session destroyed before the delete; the app is a pre-defined driver entry that cannot be removed.","solutions":["Check the wrapped NvAPI_Status; treat 'not found' statuses as already-deleted success cases.","Ensure the application struct was obtained via DRS_FindApplicationByName/enum from the SAME profile handle you pass to DeleteApplication.","Verify the session is still open and the profile exists before deleting.","Retry after re-fetching the application struct if the driver state changed concurrently."],"exampleFix":"// before\nvar caRes = nvw.Instance.DRS_DeleteApplicationEx(hSession, hProfile, ref application);\nif (caRes != NvAPI_Status.NVAPI_OK)\n    throw new NvapiException(\"DRS_DeleteApplication\", caRes);\n// after\nvar caRes = nvw.Instance.DRS_DeleteApplicationEx(hSession, hProfile, ref application);\nif (caRes == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND)\n    return; // already gone\nif (caRes != NvAPI_Status.NVAPI_OK)\n    throw new NvapiException(\"DRS_DeleteApplication\", caRes);","handlingStrategy":"try-catch","validationCode":"// ensure the app struct came from this profile\nvar found = FindApplication(hSession, hProfile, application.appName);\nif (found == null) return; // nothing to delete","typeGuard":null,"tryCatchPattern":"try { DeleteApplication(hSession, hProfile, app); }\ncatch (NvapiException ex) when (ex.Status == NvAPI_Status.NVAPI_EXECUTABLE_NOT_FOUND)\n{ /* already removed - treat as success */ }\ncatch (NvapiException ex)\n{ log.Error($\"DRS_DeleteApplicationEx failed: {ex.Status}\"); throw; }","preventionTips":["Only delete application structs obtained from the same profile handle.","Re-fetch the app struct right before deleting to avoid stale data.","Treat not-found statuses as idempotent success in callers.","Keep the DRS session open across find-then-delete sequences."],"tags":["nvapi","driver-settings","delete","native-interop"],"backgroundTag":"entity-not-found","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"}