-
Notifications
You must be signed in to change notification settings - Fork 1k
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
dotnet exec current folder issue #28315
Comments
When your Platform Invoke method has In principle, you could use NativeLibrary.SetDllImportResolver to set a resolver that recognizes the DLL name, constructs the correct path, and calls NativeLibrary.Load. However, I doubt this would be any more secure than e.g. Related reading: 2019 year-end link clearance: The different kinds of DLL planting - The Old New Thing |
Looking at the docs for |
Similar to dotnet/runtime#11540 I observe the same problem but with |
To clarify, I only self-assigned for triage. SDK gets a lot of incoming so we assign out to team members and leave them labeled untriaged. |
@elinor-fung @vitek-karas as this seems to be a question about the working directory of the host when launching an application. |
This is likely because Anything done to change what is considered the application directory (such that it doesn't match the OS platform definition) would be the same, from a security perspective, as if you were to take the options @KalleOlaviNiemitalo mentioned. |
I'm building a .net 6 console application that needs to p/Invoke into a native library. The native library lives in the same folder as my console application and so I have marked-up my native dll APIs with
[DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
.The output of my .net application has two files:
MyConsoleApp.exe
, as well asMyConsoleApp.dll
. My expectation is that I can run either of those and get an identical behaviour in terms of how my native dll is loaded. However, that is not the case.If I run
MyConsoleApp.exe
from a command prompt with the current directory set to where the executable is, everything works as expected. If I instead rundotnet exec MyConsoleApp.dll
, from the same command prompt as above, I get a DllNotFound exception for my native dll. Usingprocmon
it seems that the current directory for the case where I'm running throughdotnet
is the one wheredotnet
lives, and the folder where my app lives is not among the searched locations.Is there a way to tell
dotnet exec
what the current folder should be? I don't want to change myDefaultDllImportSearchPaths
toAssembly
because that seems to be considered a vulnerability, and I'd also like to continue running my app throughdotnet
.The text was updated successfully, but these errors were encountered: