-
Notifications
You must be signed in to change notification settings - Fork 4.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dll Search Path Behavior for Windows System Dlls for certain dotnet apps (WPF?) #101857
Comments
Tagging subscribers to this area: @vitek-karas, @agocke, @VSadov |
You may need to build a custom host for this: https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting @elinor-fung any other option for configuring the default DLL search directories? |
The startup path resulting in this is a p/invoke into kernel32. I can see this specifically for LocalAlloc as part of Because the application is deployed as self-contained, the folder containing the app is added to I don't think there is any way a user could change this for self-contained + single-file right now, since custom hosting is non-single-file. We could a make single-file not add the executable directory and handle bundled assembly p/invoke resolution in the runtime (option proposed, but not taken, in #42772). It would be a breaking change at this point though. |
Thanks for the input. It does appear upon playing with self-contained vs framework dependent that the directory being searched is affected, in that the directory containing the dotnet library is being searched instead of the directory of the exe (in the case of framework dependent). To me in a single file scenario I would expect the exe containing the directory to not be searched as it is a single exe after all, instead the temp directory where anything that is extracted should be look at. Understanding that searching the current directory could be breaking change, perhaps it could become a build/runtime config that one would have to enable, though it sounds like there may be other side effects of making such a change (since unmanaged could be force included, that location could be searched instead of current dir?) For us at least for us the scope of the issue seems to be limited to win32 libs (or things that should only be loaded from %WINDIR%\system32 and maybe certain other dirs), if the scope was limited to such libs maybe that could be a possibility (and help other app configurations in the process). |
Background
When running a self-contained WPF app, it is observed that on startup in windows the exe makes calls to what looks like to load windows DLLs. However later on it attempts to load the same windows dll from the running directory of the exe. Example for one such DLL below (there are more, probably depending on includes).
Steps to repo
Expected behavior: for critical window DLLs it should only be looking in c:\windows\system32 or other system directories
Actual behavior: it looks in the current working directory (or same directory?) as the executable.
Attempt to use things like SetDefaultDllDirectories via PInvoke does not work as the dlls are searched for before main or even static constructors are executed; suspect the dll's are being loaded at a lower level.
Ideas for fixes
Notes
The text was updated successfully, but these errors were encountered: