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.
I had this same problem for both ".NET Core 3.1" and ".NET Core 5.0".
First, try having
-c Releaseset before-r win-x64. I don't know why it is so, but that is what worked for me. So, for your example code, what it need to be is:What going on in your code-behind can also be the cause of the problem. For myself, it was the event-handler that reached out to the buttons in the title bar.