I have a simple WPF app that I want to publish as a single exe file. I invoke the command:
dotnet publish -r win-x64 -c Release -p:PublishSingleFile=true
In the end, I get the exe
and pdb
files. When I try to run the exe
, the cursor turns into "loading" state for a few seconds and... that's it. The app doesn't run. There's no error, it just doesn't start.
When I deploy the app without the "single file" option, the app works fine.
I'm using .NET Core 3.1.401
What is wrong?
//EDIT
Dependency Walker logs (I published app in x86 and used x86 Dependency Walker):
Started "ADP.WPFUI.EXE" (process 0x40FC) at address 0x00860000 by thread 1. Cannot hook module.
Loaded "NTDLL.DLL" at address 0x77C20000 by thread 1. Cannot hook module.
Loaded "KERNEL32.DLL" at address 0x759C0000 by thread 1. Cannot hook module.
Loaded "KERNELBASE.DLL" at address 0x75BC0000 by thread 1. Cannot hook module.
DllMain(0x75BC0000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNELBASE.DLL" called by thread 1.
DllMain(0x75BC0000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNELBASE.DLL" returned 1 (0x1) by thread 1.
DllMain(0x759C0000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNEL32.DLL" called by thread 1.
DllMain(0x759C0000, DLL_PROCESS_ATTACH, 0x00000000) in "KERNEL32.DLL" returned 1 (0x1) by thread 1.
Injected "DEPENDS.DLL" at address 0x08370000 by thread 1.
DllMain(0x08370000, DLL_PROCESS_ATTACH, 0x00000000) in "DEPENDS.DLL" called by thread 1.
DllMain(0x08370000, DLL_PROCESS_ATTACH, 0x00000000) in "DEPENDS.DLL" returned 1 (0x1) by thread 1.
Second chance exception 0xC0000005 (Access Violation) occurred at address 0x707AE0E0 by thread 1.
Exited "ADP.WPFUI.EXE" (process 0x40FC) with code -1073741819 (0xC0000005) by thread 1.
The problem is that the pdb-file is not packaged in the executable.
For me including this line (either in the build file or publish profile) made it work:
see: https://github.com/dotnet/sdk/issues/10523#issuecomment-535619277
You can check the source of the error in the windows EventViewer. An error for a missing pdb-file looks like this: