{"record":{"id":"a8e2d7b62af717fb","repo":"JosefNemec/Playnite","slug":"only-one-application-instance-is-allowed","errorCode":null,"errorMessage":"Only one application instance is allowed.","messagePattern":"Only one application instance is allowed\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"source/Playnite/App/PlayniteApplication.cs","lineNumber":99,"sourceCode":"        public PlayniteUriHandler UriHandler { get; }\r\n        public PlayniteAPI PlayniteApiGlobal { get; set; }\r\n        public GameControllerManager GameController { get; set; }\r\n\r\n        private ExtensionsStatusBinder extensionsStatusBinder = new ExtensionsStatusBinder();\r\n        public ExtensionsStatusBinder ExtensionsStatusBinder { get => extensionsStatusBinder; set => SetValue(ref extensionsStatusBinder, value); }\r\n\r\n        public PlayniteApplication()\r\n        {\r\n        }\r\n\r\n        public PlayniteApplication(\r\n            Func<Application> appInitializer,\r\n            ApplicationMode mode,\r\n            CmdLineOptions cmdLine)\r\n        {\r\n            if (Current != null)\r\n            {\r\n                throw new Exception(\"Only one application instance is allowed.\");\r\n            }\r\n\r\n            // TODO: remove after switch to .NET 5\r\n            // Fixes various network issues on 2004+ Win10 if TLS 1.3 is forced via registry.\r\n            if (Computer.IsTLS13SystemWideEnabled())\r\n            {\r\n                logger.Warn(\"System wide TLS 1.3 is enabled, forcing 1.2.\");\r\n                ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;\r\n            }\r\n\r\n            CmdLine = cmdLine;\r\n            Mode = mode;\r\n            Current = this;\r\n\r\n            if (!Debugger.IsAttached)\r\n            {\r\n                AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;\r\n            }\r","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/JosefNemec/Playnite/blob/5911f4e964e628aa7a69c2030ab35101afa63067/source/Playnite/App/PlayniteApplication.cs#L81-L117","documentation":"Thrown by the PlayniteApplication constructor when the static Current singleton is already set. Playnite enforces a single process-wide application instance; constructing a second PlayniteApplication is a programmer error rather than a runtime condition.","triggerScenarios":"Instantiating `new PlayniteApplication(...)` more than once in the same process / AppDomain, where the first instance already populated PlayniteApplication.Current.","commonSituations":"Test harness or tooling that spins up the application repeatedly in one process; a misuse of the SDK host embedding logic; a second startup path triggered during crash recovery.","solutions":["Reuse the existing PlayniteApplication.Current instance instead of constructing a new one.","Ensure only one construction site runs per process; guard entry points with `if (Current != null) return Current;`.","In tests, run each application instance in a separate process/AppDomain."],"exampleFix":"// before\nvar app = new PlayniteApplication(init, mode, cmdLine);\n\n// after\nvar app = PlayniteApplication.Current ?? new PlayniteApplication(init, mode, cmdLine);","handlingStrategy":"validation","validationCode":"if (PlayniteApplication.Current != null)\n{\n    return PlayniteApplication.Current;\n}\nvar app = new PlayniteApplication(init, mode, cmdLine);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat PlayniteApplication as a per-process singleton; reuse Current.","Run each instance in its own process/AppDomain in tests.","Guard all construction sites against an already-set Current."],"tags":["application","singleton","startup","playnite"],"backgroundTag":null,"analyzedSha":"5911f4e964e628aa7a69c2030ab35101afa63067","analyzedAt":"2026-08-13T17:38:25.713Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}