Directory.GetCurrentDirectory() doesn’t point to bin folder anymore

I have an ASP.Net Core 3.1 solution that uses a Docker Compose file as its startup project. Calling the method Directory.GetCurrentDirectory() from anywhere in the code returns the string /app, which is weird as I was expecting this string to include /bin/Debug/netcoreapp3.1 or (Release if I build the code in release mode). If I go into the docker container that runs the code, the executing code is located at /app/bin/Debug/netcoreapp3.1.

What is going on?


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Thanks to Canton7 in the comments above I figured out that you should call Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) instead.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x