In self-contained app Application.ExecutablePath returns dll
See original GitHub issueI’m not sure if this is bug or by design but in a self-contained app Application.ExecutablePath return path to dll and there is no apparent way to easily get path to the executable. What is recommended way to solve this problem?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:9 (6 by maintainers)
Top Results From Across the Web
c# - How to get the path of a "SelfContained" and " ...
NET Core 3.1. Self-contained .NET Core applications are automatically extracted into a temporary folder. So the path of the published executable ...
Read more >Application.ExecutablePath Can Return Wrong Path
When I run the application in the Visual Studio debugger, ExecutablePath returns the DLL path instead of the EXE path!
Read more >Create a single file for application deployment - .NET
Single-file deployment is available for both the framework-dependent deployment model and self-contained applications.
Read more >Application.ExecutablePath Property
Gets the path for the executable file that started the application, including the executable name.
Read more >How to create a single self-contained Exe-File for a ... - YouTube
How to create a single self-contained Exe-File for a .NET application ... NET Core Console App with Dependency Injection, Logging, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@Symbai The code for
Application.ExecutableImagein WinForms is already Windows only anyways, and theApplicationclass won’t be going cross-platform anytime soon either because it is based on the Windows message loop. For cross-platform there isAssembly.GetEntryAssemblyand I don’t suggest to change that.Well, the decision with Process.Start was that they wanted it to behave the same on all platforms, but only Windows has the ShellExecute support, so whatever choice they took it was going to be broken from the start.
The case here is different, the implementation already has code to look for the “right” return value (return the native exe e.g. when your DLL is running as a plugin in a native application) but it isn’t triggered because what was previoulsy an edge case is now the common case (most people didn’t write a native host which calls a main function, now you get one auto-generated).
Whether you consider it a breaking change depends on what you consider your input. If you consider the input “being a managed application” then fixing the bug is no breaking change for this input, but keeping the current behavior is a breaking change for this input. Since dotnet 3 hasn’t been released and this is new API there is no breaking change within .NET Core either. The WinForms team can of course still close the issue as ‘by design’ but I think its possible to still fix this now.
I’d consider row 2 to be a bug in Desktop Framework, but it was an edge case so nobody ever bothered to fix it. The fact that .NET Core makes row 2 the default is unfortunate but still fixable without negative impact for the common case.