dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.24k stars 1.76k forks source link

[MAUI] [WinUI] App crashes when using the startup task ability #22387

Closed ITaluone closed 6 months ago

ITaluone commented 6 months ago

Description

If I configure my maui app to run as a startup task like this:

<desktop:Extension Category="windows.startupTask" Executable="MyApp.exe"
    EntryPoint="Windows.FullTrustApplication">
    <desktop:StartupTask TaskId="my.applicationId.from.csproj" Enabled="true"
        DisplayName="My App" />
</desktop:Extension>

where the desktop xml namespace is: xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10" and my.applicationId.from.csproj matches this <ApplicationId>my.applicationId.from.csproj</ApplicationId>

I am able to enable this app as startup task in windows app settings. So far so good..

Now, if I logoff and back on I run into following error: My App shows up for like 100ms and then crashes silently. Only two messages in the event log are added.

First event log:

Application: MyApp.exe
CoreCLR Version: 8.0.324.11423
.NET Version: 8.0.3
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Runtime.InteropServices.COMException (0x80040154)
   at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
   at ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(IObjectReference _obj, ApplicationInitializationCallback callback)
   at MyApp.WinUI.Program.Main(String[] args)

Second event log in german:

Name der fehlerhaften Anwendung: MyApp.exe, Version: x.x.x.x, Zeitstempel: 0x65cd0000
Name des fehlerhaften Moduls: KERNELBASE.dll, Version: 10.0.19041.4291, Zeitstempel: 0xa956ff71
Ausnahmecode: 0xe0434352
Fehleroffset: 0x000000000002ab89
ID des fehlerhaften Prozesses: 0x4734
Startzeit der fehlerhaften Anwendung: 0x01daa5b8592e77ec
Pfad der fehlerhaften Anwendung: C:\Program Files\WindowsApps\my-app_x.x.x.x_x64__c0pwvv6r2k4z6\ctiTool2.0.exe
Pfad des fehlerhaften Moduls: C:\Windows\System32\KERNELBASE.dll
Berichtskennung: b9d7cb25-b763-4e0b-aed4-ed82b39be3bf
Vollständiger Name des fehlerhaften Pakets: my-app_x.x.x.x_x64__c0pwvv6r2k4z6
Anwendungs-ID, die relativ zum fehlerhaften Paket ist: App

Unfortunately I cannot give any more information, because everything is working when:

This config looks like this:

<uap5:Extension Category="windows.appExecutionAlias" Executable="MyApp.exe"
    EntryPoint="Windows.FullTrustApplication">
    <uap5:AppExecutionAlias>
        <uap5:ExecutionAlias Alias="MyAppAlias.exe" />
    </uap5:AppExecutionAlias>
</uap5:Extension>

where namespace uap5 is xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

8.0.21 SR4.1

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

Running with appExecutionAlias via cli on startup (as described above)

Relevant log output

No response

github-actions[bot] commented 6 months ago

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 and thumbs upping the other issue to help us prioritize it. Thank you!

Closed similar issues:

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

MartyIX commented 6 months ago

This looks like something that can be relatively easily tested in a vanilla[^1] WinUI (without MAUI) to find out if it is a MAUI bug or a WinUI bug.

[^1]: I use my testing app https://github.com/MartyIX/LineHeight202404/.

ITaluone commented 6 months ago

Now I am confused completely... I have to admit, that my app has some special cases which should be met.

So I decided to test this with a boilerplate VS MAUI-Blazor, just adding the capability for startupTask... and... it works. After this insight, I was sure it have to be one or more piece of aforementioned app capabilities, so I removed anything special to my app.. and it worked. Now, after quite a long iteration between: "Adding something back" -> "publish" -> "install the msix" -> "repeat" I am now in the initial state.. Error: gone 🤷‍♂️

Can anybody relate to this? 😆

PureWeen commented 6 months ago

Hmm good to hear your unblocked @ITaluone

Can we close this issue for now? If you're able to reproduce this in a vanilla WinUI app then we can create an issue for them

ITaluone commented 6 months ago

Hmm good to hear your unblocked

Me too... But I did nothing different... suddenly it seems to work

ITaluone commented 6 months ago

Can we close this issue for now?

Yes I guess..

I will reopen if this problem comes back