From ee711854df95858c1cc44409bc493de2382ed1e6 Mon Sep 17 00:00:00 2001 From: indep-arg <333053532+indep-arg@users.noreply.github.com> Date: Sun, 11 Oct 2026 10:06:40 -0300 Subject: [PATCH] Treat DISM as unavailable when DismApi.dll can't be loaded DismUtil.IsDismAvailable (and SupportExportAllDrivers) check for DISM with Marshal.Prelink and only handled DllNotFoundException and EntryPointNotFoundException. If the DismApi.dll found on the search path is for the other architecture, Prelink throws BadImageFormatException. Because IsDismAvailable is evaluated in the DismUtil type initializer, this surfaces as a TypeInitializationException and the app crashes on startup. Windows 8 and later always find the matching DLL in System32 first. Windows 7 has none there, so it falls back to the rest of the search path. Since the DISM menu item's state is computed at startup on every OS, a mismatched DismApi.dll anywhere on that path is enough to crash Windows 7. Catch BadImageFormatException as well and treat DISM as unavailable, so the app falls back to PnpUtil as it already does when the DLL is missing. Refs #479 --- Rapr/Utils/DismUtil.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Rapr/Utils/DismUtil.cs b/Rapr/Utils/DismUtil.cs index accb58b..0edb92b 100644 --- a/Rapr/Utils/DismUtil.cs +++ b/Rapr/Utils/DismUtil.cs @@ -41,6 +41,13 @@ public DismUtil(string imagePath) { return false; } + catch (BadImageFormatException ex) + { + // A DismApi.dll for the other architecture was found on the search path. This mostly + // happens on Windows 7, which has no DismApi.dll in System32. Treat DISM as unavailable. + Trace.TraceWarning($"DismApi.dll could not be loaded: {ex.Message}"); + return false; + } return true; })(); @@ -67,6 +74,12 @@ public DismUtil(string imagePath) { return false; } + catch (BadImageFormatException ex) + { + // Same as in IsDismAvailable. + Trace.TraceWarning($"DismApi.dll could not be loaded: {ex.Message}"); + return false; + } return true; })();