{"record":{"id":"29955a52374c4d34","repo":"TechnitiumSoftware/DnsServer","slug":"dns-application-already-exists-application-name","errorCode":null,"errorMessage":"DNS application already exists: {application.Name}","messagePattern":"DNS application already exists: (.+?)","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Applications/DnsApplicationManager.cs","lineNumber":119,"sourceCode":"            Dispose(true);\n        }\n\n        #endregion\n\n        #region private\n\n        private async Task<DnsApplication> LoadApplicationAsync(string applicationFolder, bool refreshAppObjectList)\n        {\n            string applicationName = Path.GetFileName(applicationFolder);\n\n            DnsApplication application = new DnsApplication(new InternalDnsServer(_dnsServer, applicationName, applicationFolder), applicationName);\n\n            await application.InitializeAsync();\n\n            if (!_applications.TryAdd(application.Name, application))\n            {\n                application.Dispose();\n                throw new DnsServerException(\"DNS application already exists: \" + application.Name);\n            }\n\n            application.ConfigUpdated += Application_ConfigUpdated;\n\n            if (refreshAppObjectList)\n                RefreshAppObjectLists();\n\n            return application;\n        }\n\n        private void UnloadApplication(string applicationName)\n        {\n            if (!_applications.TryRemove(applicationName, out DnsApplication removedApp))\n                throw new DnsServerException(\"DNS application does not exists: \" + applicationName);\n\n            RefreshAppObjectLists();\n\n            removedApp.ConfigUpdated -= Application_ConfigUpdated;","sourceCodeStart":101,"sourceCodeEnd":137,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Applications/DnsApplicationManager.cs#L101-L137","documentation":"Thrown by DnsApplicationManager.LoadApplicationAsync when an application with the same name is already registered (TryAdd on the concurrent application map fails). The freshly loaded application is disposed and the duplicate load is aborted to keep names unique.","triggerScenarios":"Loading/installing a DNS application whose name collides with one already in _applications: concurrent installs, re-install without uninstall, filesystem containing two app folders resolving to the same name, or a race during refresh.","commonSituations":"Re-running an installer that did not clean up, duplicate folders under the apps path, parallel API calls installing the same app, or a hot-reload that re-adds an existing app.","solutions":["Uninstall (UnloadApplication) the existing application before installing/loading the same name.","Guard the install with a ContainsKey check (and expect a possible race).","Ensure only one app folder per name on disk.","Serialize install/load operations to avoid concurrent duplicate adds."],"exampleFix":"// before\nawait manager.InstallApplicationAsync(name, zip); // throws if exists\n\n// after\nif (!manager.Applications.ContainsKey(name))\n    await manager.InstallApplicationAsync(name, zip);\nelse\n    await manager.UnloadApplication(name).ContinueWith(_ => manager.InstallApplicationAsync(name, zip)).Unwrap();","handlingStrategy":"validation","validationCode":"if (manager.Applications.ContainsKey(name))\n    throw new InvalidOperationException(\"Application already installed: \" + name);\nawait manager.InstallApplicationAsync(name, zip);","typeGuard":"static bool ApplicationNotInstalled(DnsApplicationManager m, string name)\n    => !m.Applications.ContainsKey(name);","tryCatchPattern":"try { await manager.InstallApplicationAsync(name, zip); }\ncatch (DnsServerException ex) when (ex.Message.Contains(\"already exists\"))\n{ await manager.UnloadApplication(name); await manager.InstallApplicationAsync(name, zip); }","preventionTips":["Uninstall before reinstalling the same application name.","Serialize install operations to avoid concurrent duplicate adds.","Keep a single app folder per name on disk."],"tags":["dns","application","validation","duplicate","state"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}