microsoft / microsoft-ui-xaml

WinUI: a modern UI framework with a rich set of controls and styles to build dynamic and high-performing Windows applications.
MIT License
6.38k stars 683 forks source link

WinUI3 application is failed to start from command line #9348

Closed mimregit closed 9 months ago

mimregit commented 9 months ago

Describe the bug

I created a sample application, there was nothing special, just do it with the wizard, named AppTest. The only modification was to add the appExecutionAlias extension to the package manifest file:

<Extensions>
    <uap5:Extension
      Category="windows.appExecutionAlias"
      Executable="AppTest.exe"
      EntryPoint="AppTest.App">
        <uap5:AppExecutionAlias>
            <uap5:ExecutionAlias Alias="AppTest.exe" />
        </uap5:AppExecutionAlias>
    </uap5:Extension>
</Extensions>

Started the app from the Visual Studio wroked well. Launched a command prompt, and typed in: AppTest

Weird results are:

  1. The operating system starts 2 instances of the application, the first is suspended initially, the second runs, but turns into suspended mode in 3 seconds, then immediately closed.
  2. There is no other effect on the screen.
  3. There is a .NET Runtime error on the Event Viever, saying called a thread attached to an other thread: Application: AppTest.exe CoreCLR Version: 6.0.2724.6912 .NET Version: 6.0.27 Description: The process was terminated due to an unhandled exception. Exception Info: System.Runtime.InteropServices.COMException (0x8001010E): Az alkalmazás olyan objektumfelületet hívott, amely egy másik szálhoz volt rendelve.

The Application Object must initially be accessed from the multi-thread apartment. at WinRT.ExceptionHelpers.g__Throw|39_0(Int32 hr) at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr) at ABI.Microsoft.UI.Xaml.IApplicationStaticsMethods.Start(IObjectReference _obj, ApplicationInitializationCallback callback) at Microsoft.UI.Xaml.Application.Start(ApplicationInitializationCallback callback) at AppTest.Program.Main(String[] args)

Please, Microsoft, this problem has a predecessor, and I found never a solution on any forum!

At this moment it is impossible to launch from command line any WinUI application, although it would be necessary. How can we solve this problem?

Steps to reproduce the bug

  1. Create any WinUI app
  2. Modify package.manifest
  3. Run the app once
  4. Open a command line and try to launch

Expected behavior

No response

Screenshots

image image

NuGet package version

WinUI 3 - Windows App SDK 1.4.5: 1.4.240411001

Windows version

Windows 11 (22H2): Build 22621

Additional context

No response

github-actions[bot] commented 9 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. Thank you!

Closed similar issues:

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

lhak commented 9 months ago

I think you need to set your EntryPoint to "Windows.FullTrustApplication".

mimregit commented 9 months ago

I think you need to set your EntryPoint to "Windows.FullTrustApplication".

That helps, thank you!!