Ambiguous "os error 126" when native mods have missing dependencies
Ran into this situation while testing an (unintended) debug build of a mod.
$ PROTON_LOG=1 me3 launch -g er -n mods/NoCompass-1.1/NoCompass.dll
...
INFO run: me3_launcher: attached to game successfully
WARN me3_mod_host: failed to load native mod error=LoadLibraryExW failed error.sources=[Module not found. (os error 126)] path=/home/jn/games/elden-ring/mods/NoCompass-1.1/NoCompass.dll
ERROR me3_mod_host: deferred attach failed! error=LoadLibraryExW failed error.sources=[Module not found. (os error 126)]
The error sounds like the mod DLL itself isn't found, which shouldn't be possible; me3 should fail first if the path is invalid and the mod is not optional. But users don't exactly know that.
From the Proton log, it becomes clear the DLL has missing dependencies:
38895.862:0164:0168:err:module:import_dll Library MSVCP140D.dll (which is needed by L"Z:\home\jn\games\elden-ring\mods\NoCompass-1.1\NoCompass.dll") not found
38895.863:0164:0168:err:module:import_dll Loading library VCRUNTIME140D.dll (which is needed by L"Z:\home\jn\games\elden-ring\mods\NoCompass-1.1\NoCompass.dll") failed (error c000007b).
38895.863:0164:0168:err:module:import_dll Library VCRUNTIME140_1D.dll (which is needed by L"Z:\home\jn\games\elden-ring\mods\NoCompass-1.1\NoCompass.dll") not found
38895.863:0164:0168:err:module:import_dll Library ucrtbased.dll (which is needed by L"Z:\home\jn\games\elden-ring\mods\NoCompass-1.1\NoCompass.dll") not found
I'm not sure how Windows users would discover the underlying issue.
These are Windows functions and error codes, but the output might differ between wine and Windows.
The "bad" debug build of the mod, if anyone wants to test on Windows:
https://github.com/Logersnamed/EldenRing-NoCompass-Mod/releases/tag/v1.1
It depends on debug DLLs from Visual Studio (not to be confused with similar DLLs from Visual C++ Redistributables without the D suffix), so make sure you don't have those debug DLLs to repro the error.
I'm unsure if LoadLibrary on a missing file presents itself differently from LoadLibrary on a file with missing dependencies, but we could at least catch the 126 on the load and report that it didn't come from the DLL itself.