microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

Published unpackaged app in Single File does not execute

Open UltraWelfare opened this issue 1 year ago • 12 comments

Describe the bug

Publishing an unpackaged application with it being a Single File makes the executable not being able to launch... Publishing it without it being Single File works correctly and it launches fine. Trimming and ReadyToRun have no change on whether the single file works or not.

Steps to reproduce the bug

  1. Create new project
  2. Open .csproj file and add:
<WindowsPackageType>None</WindowsPackageType>
<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  1. Make a new profile (debug / release doesn't matter) Target framework: net8.0-windows10.0.19041.0 Deployment mode: self-contained Target runtime: win-x64 File publish options: Check Produce single file, the rest don't matter

  2. Publish (it will build correctly) but opening the executable does not work.

Expected behavior

The executable to launch correctly.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.6.2: 1.6.241106002

Windows version

No response

Additional context

Windows version is: 23H2 (for some reason it wasn't an option in the select dropdown) VS2022 version: 17.12.0 dotnet sdk: 8.0.404

Project is attached: project.zip (edit: had to reupload the project.zip because it didn't include the publish profile)

UltraWelfare avatar Nov 16 '24 10:11 UltraWelfare

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

github-actions[bot] avatar Nov 16 '24 10:11 github-actions[bot]

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Closed similar issues:

* [Using Win2D breaks publishing unpackaged app as single file (#6400)](https://github.com/microsoft/microsoft-ui-xaml/issues/6400),  similarity score: 0.81

* [Publishing an unpackaged winUI 3 project yields an exe that causes an error on run (#6735)](https://github.com/microsoft/microsoft-ui-xaml/issues/6735),  similarity score: 0.81

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

I've just taken a look at the second issue here. The difference is I get no error on launching the executable. It shows the "loading spinner" in the mouse, and then just disappears without ever launching. Launching the exe from the terminal (PS / cmd) shows no output as well

UltraWelfare avatar Nov 16 '24 10:11 UltraWelfare

I've tried debugging the executable, separate from the project. Image I'm not sure what to do with this information, but I tried digging in more deeply but it seems like there's something going outside the application code: Image

Although I can't go on further because I don't have some pdbs for System.Private.CoreLib.ni.pdb

Update: Image

Seems like the inner exception is coming from NameHandle::GetTypeToken(void) but I can't find any other information about it

Update 2: Image This is what I got from the Event Viewer

Update 3: Managed to get a dmp from the crash App1.exe.103104.dmp

UltraWelfare avatar Nov 16 '24 11:11 UltraWelfare

IIRC this is still an unsupported scenario.

Balkoth avatar Nov 17 '24 18:11 Balkoth

IIRC this is still an unsupported scenario.

It is supported afaik. Through the official C# discord server, another member confirmed that he could make an executable with this configuration work normally...

UltraWelfare avatar Nov 17 '24 18:11 UltraWelfare

Have you tried deleting the obj and bin folder? I have seen issues when switching between single file configuration turned on and off causing the resulting app to crash at start.

lhak avatar Nov 17 '24 19:11 lhak

Might want to look into this: https://github.com/microsoft/WindowsAppSDK/discussions/3886#discussioncomment-7134451

Balkoth avatar Nov 17 '24 19:11 Balkoth

@Balkoth The 1.5 release notes states unqualified that single file publishing is supported. The comment that was linked is about from the time frame of 1.4.

DarranRowe avatar Nov 18 '24 01:11 DarranRowe

Must have missed that, thanks.

Balkoth avatar Nov 18 '24 08:11 Balkoth

Attached is a project where i stripped everything i deemed unnecessary, and that runs when published as single file. Perhaps you can mod in your changes from your sample and see where it breaks down? TestPubSingleFIle.zip

Balkoth avatar Nov 19 '24 16:11 Balkoth

I'm running into the same issue here. Publishing as self-contained works, publishing as self-contained single EXE fails to launch with the following exception:

CoreCLR Version: 8.0.1325.6609
.NET Version: 8.0.13
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileNotFoundException: The specified module could not be found.

   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(Int32 errorCode)
   at WinRT.ActivationFactory.Get(String typeName, Guid iid)
   at Microsoft.Windows.AppLifecycle.AppInstance.get__objRef_global__Microsoft_Windows_AppLifecycle_IAppInstanceStatics()
   at Microsoft.Windows.AppLifecycle.AppInstance.GetCurrent()

Looking at this more closely in the Process Monitor, it is trying to load Microsoft.WindowsAppRuntime.dll from the folder with the single EXE file instead of looking into the temporary folder where the content of the single EXE file gets extracted (AppData\Local\Temp\net).

jimm98y avatar Feb 17 '25 09:02 jimm98y

I'm having the same issue.

Here's my dump file:

Shelf.exe.71000.dmp

After trying around a bit, I noticed that the app actually runs, if I first use a normal release build, then build a published self-contained .exe and copy it in the folder of the previously built release build folder.

To me it seems, that the malfunctioning .exe tries to find some .dll, but I have no idea of how to find out which one.

Notice: When using the option "Trim unused code" in the publish section of VS 2022, there occurs a totally different error. So if you want to reproduce, do not tick that checkbox.

radlog avatar Jun 15 '25 17:06 radlog

Same issue. With "single file" the app doesnt start.

LDelPinoNT avatar Sep 15 '25 14:09 LDelPinoNT