From 9d5742543db9108361e9f4fd3a67c7c76b247df7 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 7 Mar 2021 15:49:38 +0530 Subject: [PATCH] DnsServerSystemTrayApp: fixes issue with appPath due to net5 upgrade. --- DnsServerSystemTrayApp/Program.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/DnsServerSystemTrayApp/Program.cs b/DnsServerSystemTrayApp/Program.cs index 4be5c05e..55766ea8 100644 --- a/DnsServerSystemTrayApp/Program.cs +++ b/DnsServerSystemTrayApp/Program.cs @@ -1,6 +1,6 @@ /* Technitium DNS Server -Copyright (C) 2019 Shreyas Zare (shreyas@technitium.com) +Copyright (C) 2021 Shreyas Zare (shreyas@technitium.com) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,7 +18,6 @@ along with this program. If not, see . */ using System; -using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Reflection; @@ -34,7 +33,7 @@ namespace DnsServerSystemTrayApp const string MUTEX_NAME = "TechnitiumDnsServerSystemTrayApp"; - static readonly string _appPath = Assembly.GetEntryAssembly().Location; + static string _appPath = Assembly.GetEntryAssembly().Location; static readonly bool _isAdmin = (new WindowsPrincipal(WindowsIdentity.GetCurrent())).IsInRole(WindowsBuiltInRole.Administrator); static Mutex _app; @@ -45,6 +44,9 @@ namespace DnsServerSystemTrayApp [STAThread] public static void Main(string[] args) { + if (_appPath.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) + _appPath = _appPath.Substring(0, _appPath.Length - 4) + ".exe"; + Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); @@ -82,15 +84,13 @@ namespace DnsServerSystemTrayApp Application.Exit(); return; } - catch (Win32Exception) - { } catch (Exception ex) { MessageBox.Show("Error! " + ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } //user cancels UAC or exception occurred - _app = new Mutex(true, MUTEX_NAME, out bool createdNewMutex); + _app = new Mutex(true, MUTEX_NAME, out _); } #endregion