Skip to content
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

How to get startup path from assembly in Single Exe File #30448

Closed
OmidID opened this issue Aug 1, 2019 · 4 comments
Closed

How to get startup path from assembly in Single Exe File #30448

OmidID opened this issue Aug 1, 2019 · 4 comments
Milestone

Comments

@OmidID
Copy link

OmidID commented Aug 1, 2019

I don't know is it a bug or not.
After I published my application using this command dotnet publish -r win-x64 -c Release /p:PublishSingleFile=true I'm not able to get the correct startup address from the code below:

var executablePath = Path.GetFullPath(typeof(Program).Assembly.Location);

The output is in the temp directory and it's dll file. Something like this:
C:\Users\MyUser\AppData\Local\Temp\.net\MyApp\po5w3wnz.iiu\MyApp.dll

@khellang
Copy link
Member

khellang commented Aug 1, 2019

I guess this is because it's basically embedding the DLL in a generated assembly and extracting it to a temp location before loading the DLL. Seems like it's a known issue; https://github.com/dotnet/coreclr/issues/20287#issuecomment-504287272

@Symbai
Copy link

Symbai commented Aug 1, 2019

It's not an issue rather a breaking change if you come from .NET Framework and dot net team suggests to use GetModuleFileNameW API is Process.GetCurrent().Mainmodule.Filename.

@OmidID
Copy link
Author

OmidID commented Aug 1, 2019

Yea, this is what I already did in my code. I created this issue because I wasn't sure the assembly location should be the execution file or extracted one.

@khellang
Copy link
Member

khellang commented Aug 1, 2019

I wasn't sure the assembly location should be the execution file or extracted one.

Well, you did ask for the location of the assembly containing Program, which is the extracted assembly. If you want the executing assembly, you might want to use on of the static Assembly methods.

@OmidID OmidID closed this as completed Aug 2, 2019
@msftgits msftgits transferred this issue from dotnet/corefx Feb 1, 2020
@msftgits msftgits added this to the 3.0 milestone Feb 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 12, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants