From 4b4b3720da601d8acc97387490590151cc4cd09f Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 2 Feb 2025 16:00:05 +0530 Subject: [PATCH] DnsApplicationAssemblyLoadContext: fixed unmanaged dll loading issue on Linux that could cause DNS server to crash. --- .../Applications/DnsApplicationAssemblyLoadContext.cs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/DnsServerCore/Dns/Applications/DnsApplicationAssemblyLoadContext.cs b/DnsServerCore/Dns/Applications/DnsApplicationAssemblyLoadContext.cs index fb8e51b9..677479ea 100644 --- a/DnsServerCore/Dns/Applications/DnsApplicationAssemblyLoadContext.cs +++ b/DnsServerCore/Dns/Applications/DnsApplicationAssemblyLoadContext.cs @@ -201,12 +201,10 @@ namespace DnsServerCore.Dns.Applications { if (!_loadedUnmanagedDlls.TryGetValue(unmanagedDllPath.ToLowerInvariant(), out IntPtr value)) { - //load the unmanaged DLL - - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - value = LoadUnmanagedDllFromPath(GetTempDllFile(unmanagedDllPath)); - else - value = LoadUnmanagedDllFromPath(unmanagedDllPath); + //load the unmanaged DLL via temp file + // - to allow uninstalling/updating app at runtime on Windows + // - to avoid dns server crash issue when updating apps on Linux + value = LoadUnmanagedDllFromPath(GetTempDllFile(unmanagedDllPath)); _loadedUnmanagedDlls.Add(unmanagedDllPath.ToLowerInvariant(), value); } @@ -221,7 +219,6 @@ namespace DnsServerCore.Dns.Applications private string GetTempDllFile(string dllFile) { - //copy dll into temp file for loading to allow uninstalling/updating app at runtime. string tempPath = Path.GetTempFileName(); using (FileStream srcFile = new FileStream(dllFile, FileMode.Open, FileAccess.Read))