{"record":{"id":"458cac36032362ef","repo":"TechnitiumSoftware/DnsServer","slug":"dns-application-already-exists-applicationname","errorCode":null,"errorMessage":"DNS application already exists: {applicationName}","messagePattern":"DNS application already exists: (.+?)","errorType":"exception","errorClass":"DnsServerException","httpStatus":null,"severity":"error","filePath":"DnsServerCore/Dns/Applications/DnsApplicationManager.cs","lineNumber":375,"sourceCode":"                    }\n                }));\n            }\n\n            await Task.WhenAll(tasks);\n\n            RefreshAppObjectLists();\n        }\n\n        public async Task<DnsApplication> InstallApplicationAsync(string applicationName, Stream appZipStream)\n        {\n            foreach (char invalidChar in Path.GetInvalidFileNameChars())\n            {\n                if (applicationName.Contains(invalidChar))\n                    throw new DnsServerException(\"The application name contains an invalid character: \" + invalidChar);\n            }\n\n            if (_applications.ContainsKey(applicationName))\n                throw new DnsServerException(\"DNS application already exists: \" + applicationName);\n\n            string applicationFolder = Path.GetFullPath(Path.Combine(_appsPath, applicationName));\n            if (!applicationFolder.StartsWith(_appsPath + Path.DirectorySeparatorChar))\n                throw new DnsServerException(\"The application name is invalid: \" + applicationName);\n\n            if (Directory.Exists(applicationFolder))\n                Directory.Delete(applicationFolder, true);\n\n            Directory.CreateDirectory(applicationFolder);\n\n            //keep a copy of the zip file in the application folder for transferring to other nodes\n            await using (FileStream zipCopyStream = new FileStream(Path.Combine(applicationFolder, applicationName + \".zip\"), FileMode.Create, FileAccess.ReadWrite))\n            {\n                await appZipStream.CopyToAsync(zipCopyStream);\n\n                zipCopyStream.Position = 0;\n\n                await using (ZipArchive appZip = new ZipArchive(zipCopyStream, ZipArchiveMode.Read, false, Encoding.UTF8))","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/TechnitiumSoftware/DnsServer/blob/d0484b6c1e7439cdc53d67d81e9c876cda2ad756/DnsServerCore/Dns/Applications/DnsApplicationManager.cs#L357-L393","documentation":"Thrown by InstallApplicationAsync when an entry for the given applicationName already exists in the in-memory _applications dictionary. The DNS server treats each installed application (DNS App) as uniquely named; a duplicate name is rejected before any filesystem write so the existing install is not corrupted.","triggerScenarios":"Calling InstallApplicationAsync(name, zipStream) twice with the same name without first calling UninstallApplicationAsync. Or an automated/HA node re-running install after the dictionary was populated from a previously synced app folder on startup.","commonSituations":"Re-uploading a zip through the web UI thinking it will 'upgrade'; scripting node-to-node app replication that calls install instead of update; a half-uninstalled app whose directory was deleted but whose entry was retained (rare).","solutions":["If you want to replace the app, call UpdateApplicationAsync(name, zipStream) instead of InstallApplicationAsync.","Call UninstallApplicationAsync(name) first, then InstallApplicationAsync.","Check DnsApplicationManager (or the apps API listing) before installing and skip when the name is already present.","Restart the server if you suspect _applications is stale relative to disk (e.g. directory was manually removed)."],"exampleFix":"// before\nawait appManager.InstallApplicationAsync(name, zip);\n\n// after\nif (appManager.ListApplications().Any(a => a.Name == name))\n    await appManager.UpdateApplicationAsync(name, zip);\nelse\n    await appManager.InstallApplicationAsync(name, zip);","handlingStrategy":"validation","validationCode":"bool AppExists(IApplicationManager mgr, string name) => mgr.ListApplications().Any(a => a.Name == name);\n// call: if (AppExists(mgr, name)) await mgr.UpdateApplicationAsync(name, zip); else await mgr.InstallApplicationAsync(name, zip);","typeGuard":null,"tryCatchPattern":"try { await mgr.InstallApplicationAsync(name, zip); }\ncatch (DnsServerException ex) when (ex.Message.Contains(\"already exists\")) { await mgr.UpdateApplicationAsync(name, zip); }","preventionTips":["Branch on existence: update if present, install if absent.","Drive app deploys through a single install-or-update helper to avoid duplicate-install calls.","Treat applicationName as an immutable key per app."],"tags":["dns-app","install","duplicate","state-conflict"],"backgroundTag":null,"analyzedSha":"d0484b6c1e7439cdc53d67d81e9c876cda2ad756","analyzedAt":"2026-08-13T22:57:35.508Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}