{"record":{"id":"98378800e9693332","repo":"Orbmu2k/nvidiaProfileInspector","slug":"nvapi-bug-mitigation-failed-to-restore-application","errorCode":null,"errorMessage":"NVAPI Bug mitigation failed to restore application '{appToRestore.appName}' in profile '{profile.profileName}'","messagePattern":"NVAPI Bug mitigation failed to restore application '(.+?)' in profile '(.+?)'","errorType":"exception","errorClass":"ApplicationException","httpStatus":null,"severity":"error","filePath":"nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs","lineNumber":326,"sourceCode":"                if (app.appName.Equals(exeOnly, StringComparison.InvariantCultureIgnoreCase))\n                {\n                    DeleteApplication(hSession, otherProfile, app);\n                    appToRestore = app;\n                    break;\n                }\n            }\n\n            if (appToRestore.version == 1) return false;\n\n            var resCurrentProfile = nvw.Instance.DRS_CreateApplication(hSession, hProfile, ref pApplication);\n            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;","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/Orbmu2k/nvidiaProfileInspector/blob/2f50c388b3a4d661cade66b32746bec096d1eee1/nvidiaProfileInspector/Common/DrsSettingsServiceBase.cs#L308-L344","documentation":"ApplicationException thrown when the second half of MitigateNvapiAlreadyInUseBug fails: after re-adding the app to the current profile, the code fails to restore it in 'otherProfile' (the profile that previously held it). This leaves the app registered in the current profile but missing from its original profile. The message includes the app name and the resolved profile name.","triggerScenarios":"DRS_CreateApplication(hSession, otherProfile, ref appToRestore) returns non-OK during the mitigation restore step — invalid otherProfile handle (e.g. the original profile was deleted), the app got re-registered elsewhere concurrently, or a driver-side registration failure.","commonSituations":"The original profile was deleted or renamed between capturing otherProfile and restoring; concurrent tools modifying profiles; driver bug recurrence during restore; session invalidated mid-mitigation.","solutions":["Verify otherProfile is still valid (DRS_GetProfileInfo) before restoring; re-locate the profile by name if it was recreated.","Manually re-add the application to the original profile afterwards, since the current-profile add already succeeded.","Retry the restore step; transient driver failures are common here.","Update GPU drivers to a version where the already-in-use bug is fixed to avoid entering mitigation at all."],"exampleFix":"// before\nvar resOtherProfile = nvw.Instance.DRS_CreateApplication(hSession, otherProfile, ref appToRestore);\nif (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// after\nvar resOtherProfile = nvw.Instance.DRS_CreateApplication(hSession, otherProfile, ref appToRestore);\nif (resOtherProfile == NvAPI_Status.NVAPI_EXECUTABLE_ALREADY_ON_PROFILE)\n    return true;\nif (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}","handlingStrategy":"fallback","validationCode":"// confirm the other profile still exists before restore\nvar otherInfo = GetProfileInfo(hSession, otherProfile);","typeGuard":null,"tryCatchPattern":"try { AddApplication(hSession, hProfile, appName, folder); }\ncatch (ApplicationException ex) when (ex.Message.Contains(\"failed to restore\"))\n{ // app was added to current profile but not restored; re-add manually to the original profile\n  log.Warn(ex.Message); }","preventionTips":["Verify otherProfile validity immediately before the restore call.","Avoid deleting/renaming profiles while an AddApplication mitigation is in progress.","After a restore failure, manually re-add the app to the original profile.","Update drivers to versions without the already-in-use bug."],"tags":["nvapi","driver-bug","workaround","profile"],"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"}