Fody/Costura

Use `LoadLibraryEx` for preloading unmanaged libraries

0xced opened this issue · 3 comments

0xced commented

Summary

In #726 (comment), Tom Englert suggested to use LoadLibraryEx instead of LoadLibrary to preload unmanaged libraries:

In Costura SetDllDirectory + LoadLibrary is used. Using LoadLibraryEx(..., LOAD_WITH_ALTERED_SEARCH_PATH) might be the better solution, and PreLoadOrder would not be required here.
Any idea why it was done this way?

I think it would be a good idea to investigate this idea.

API Changes

Not really applicable, this is internal Costura stuff.

Maybe we could deprecate the PreLoadOrder configuration if it turns out that LoadLibraryEx with LOAD_WITH_ALTERED_SEARCH_PATH solves the problem of preloading dependent unmanaged libraries.

Intended Use Case

When unmanaged libraries are preloaded by Costura it would be nice to have Costura automatically load all the unmanaged libraries even if they have interdependencies and not be forced to compute a working preload order. See #726 (comment) for a good example of interdependent libraries to load.

This is a great idea and I am happy to help out / review wherever I can to get this supported.

I will provide a PR tomorrow or Friday

I got it already working, just some fine tuning left