简体   繁体   中英

Single File publish doesn't work with a WPF app

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 Release set 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:

dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true

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.

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:

<PropertyGroup>
    <IncludeSymbolsInSingleFile>true</IncludeSymbolsInSingleFile>
</PropertyGroup>

see: https://github.com/do.net/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:

Description: A .NET Core application failed.
Application: program.exe
Path: C:\path\to\program.exe
Message: Error:
  An assembly specified in the application dependencies manifest (program.deps.json) was not found:
    package: 'Microsoft.Data.SqlClient.SNI.runtime', version: '2.0.1'
    path: 'runtimes/win-x64/native/Microsoft.Data.SqlClient.SNI.pdb'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM