Skip to content

Treat DISM as unavailable when DismApi.dll can't be loaded - #480

Merged
lostindark merged 1 commit into
lostindark:masterfrom
indep-arg:fix/479
Oct 11, 2026
Merged

lostindark merged 1 commit into
lostindark:masterfrom
indep-arg:fix/479

Conversation

@indep-arg

Copy link
Copy Markdown
Contributor

Fixes #479. The crash signature the reporter posted (method token 0x19a in Rapr 1.0.36.0) resolves to DismUtil.<.cctor>b__29_0, the IsDismAvailable check, and BadImageFormatException there can only come from Marshal.Prelink failing to load DismApi.dll.


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 lostindark#479
@indep-arg indep-arg mentioned this pull request Oct 11, 2026
@indep-arg

indep-arg commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor Author

The reporter confirmed in #479 that the CI build from this PR starts normally on their Win 7 x64 machine, so the fix is verified on the affected system. Ready to merge whenever you are :)

@lostindark
lostindark merged commit 80e81f7 into lostindark:master Oct 11, 2026
2 checks passed
@indep-arg
indep-arg deleted the fix/479 branch October 11, 2026 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash at startup

2 participants