question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In self-contained app Application.ExecutablePath returns dll

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
weltkantecommented, Jun 25, 2019

@Symbai The code for Application.ExecutableImage in WinForms is already Windows only anyways, and the Application class won’t be going cross-platform anytime soon either because it is based on the Windows message loop. For cross-platform there is Assembly.GetEntryAssembly and I don’t suggest to change that.

1reaction
weltkantecommented, Jun 24, 2019

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.

Scenario Desktop Framework .NET Core current .NET Core with fix
managed application EXE DLL EXE
native application calling managed Main DLL DLL EXE
native application calling other managed code (e.g. plugins or COM objects) EXE EXE EXE

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found