Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashes when run from cmd-line (as opposed to start) #1062

Closed
ivberg opened this issue Jul 12, 2021 · 11 comments
Closed

App crashes when run from cmd-line (as opposed to start) #1062

ivberg opened this issue Jul 12, 2021 · 11 comments
Assignees

Comments

@ivberg
Copy link

ivberg commented Jul 12, 2021

Describe the bug
App crashes when run from cmd-line (as opposed to start)

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create a new C# project using instructions at https://aka.ms/winui (Try WinUI3).
  2. Use MSIX packaged app template
  3. Launch sample app from Start Menu <- OK
  4. Right click sample app in Task Mgr "Open File Location" to find .exe path
  5. In cmd-prompt run app .exe - e.g. c:\Path\To\MyApp.exe <- PROBLEM app will crash
  6. Dump show crash not in app code but in WinUI code

0d coreclr!RaiseTheExceptionInternalOnly+0x29a
0e coreclr!RealCOMPlusThrowWorker+0x31
0f coreclr!RealCOMPlusThrow+0x8d
10 coreclr!RealCOMPlusThrow+0x99
11 coreclr!TryCallMethod+0x1160f6
12 coreclr!RuntimeTypeHandle::CreateInstance+0x26d
13 System_Private_CoreLib!System.RuntimeType.CreateInstanceDefaultCtorSlow+0x48
14 System_Private_CoreLib!System.RuntimeType.CreateInstanceDefaultCtor+0xd3
15 System_Private_CoreLib!System.Activator.CreateInstance<System.__Canon>+0x3e
16 Microsoft_WinUI!WinRT.WeakLazy<_IApplicationStatics>.get_Value+0xb0
17 Microsoft_WinUI!Microsoft.UI.Xaml.Application._IApplicationStatics.get_Instance+0x38
18 Microsoft_WinUI!Microsoft.UI.Xaml.Application.Start+0x19
19 MyApp!MyApp.Program.Main+0xf2

This blocks automation and GUI Unit Testing say with something like WinAppDriver & Appium to test WinUI3 app

Expected behavior
AppSDK app launched from command prompt does not crash

Version Info
0.5.7

NuGet package version:
0.5.7

Windows app type:

UWP Win32
Yes
Windows 11 version Saw the problem?
Insider Build (22141.1000) Yes
Device form factor Saw the problem?
Desktop Yes

Additional context

@StephenLPeters
Copy link

This is currently not supported, the exe generated by the build is not an unpackaged app, which is a requirement for running an exe from the command line. You should be able to use the IApplicationActivationManager interface to launch your apps though.

@StephenLPeters
Copy link

This will also work for desktop packaged apps: https://docs.microsoft.com/en-us/windows/uwp/xbox-apps/automate-launching-uwp-apps

@ivberg
Copy link
Author

ivberg commented Jul 13, 2021

This @StephenLPeters this info definitely helps to work around the issue. I would suggest the framework not crash in this scenario, but instead simply exit. Best would be to show window stating info on how to launch it.

@MikeHillberg MikeHillberg transferred this issue from microsoft/microsoft-ui-xaml Jul 14, 2021
@MikeHillberg
Copy link
Contributor

Transferring to the WindowsAppSDK repo to see about getting a message when trying to directly launch the .exe of a packaged app.

@ivberg
Copy link
Author

ivberg commented Jul 15, 2021

Also, I wonder if this will be supported in 1.0? The docs / roadmap seem to imply it will.

Here is how I arrived at that conclusion but feel free to correct the docs or me if I am wrong.

  1. The roadmap https://github.com/microsoft/WindowsAppSDK/blob/main/docs/roadmap.md lists AppLifeCycle as Experimental for 0.8 and supported for 1.0
  2. AppLifeCycle docs - App Lifecycle #111
  3. Talk about this scenario and say things like the following
This proposal will allow users to activate any app by double-clicking it in file explorer, or typing in a path in a command window. Must
5. In the Win32 world, it is normal to activate an app by calling CreateProcess (or ShellExecute), specifying the filesystem path to the executable file. When the user double-clicks an executable file in File Explorer, this uses that same mechanism. When the user types in an executable file name into a command window, the same thing happens
  1. We will provide a converged GetActivatedEventArgs which will get all args, regardless of activation kind -- including both traditional command-line activation and also the richer UWP activation objects. This will be available to all apps.

@ivberg
Copy link
Author

ivberg commented Jul 15, 2021

Interestingly enough I just tried this on 0.8.1 stable - it seems to be halfway there now!

  1. Now working in 0.8.1 - Launch from cmd-line - now works! - C:\Program Files\WindowsApps\MyApp_1.0.0.0_x64__ms1afnmeykq8t\MyAppUI\MyAppUI.exe
  2. Still not working. Launch in explorer (for the same file path) and you get "Windows cannot access the specified device, path, or file. You may not have appropriate permissions to access the item"

@sylveon
Copy link

sylveon commented Jul 21, 2021

You can use an app execution alias inside your appx manifest if CLI launch is crucial to your app.

@DrusTheAxe
Copy link
Member

AppLifecycle and unpackaged apps are supported as of 1.0

@rcohn
Copy link

rcohn commented Feb 23, 2022

Hi @DrusTheAxe -

I see that this issue is closed, but could you possibly provide a bit more detail on your final comment "AppLifecycle and unpackaged apps are supported as of 1.0"?

Today I built a WinUI3 unpackaged app and, while I'm able to double click on it to start it from File Explorer, I cannot start it up from a cmd prompt or script. I do see the comments above about IApplicationActivationManager, so that's something I intend to try.

But if you have any more info on unpackaged apps deployment for Windows App SDK 1.0, I would be grateful to hear them.

Thanks very much.

@DrusTheAxe
Copy link
Member

Today I built a WinUI3 unpackaged app

Using the 1.0 Stable release (not experimental or preview or previous releases)?

Unpackaged apps require Dynamic Dependencies and the Bootstrapper API e.g. MddBootstrapInitialize(), which were introduced in 1.0. Won't work on earlier versions (e.g. 0.8).

while I'm able to double click on it to start it from File Explorer, I cannot start it up from a cmd prompt or script

Is it a normal cmd prompt or did you Run as Administrator (aka elevated)? The latter won't work in 1.0 (elevation support for unpackaged apps is coming in 1.1)

What version of Windows are you running on?

I do see the comments above about IApplicationActivationManager

That's only relevant if you're a packaged app. If you are then your application can be launched via AAM (same as when you clikc on the StartMenu tile for your packaged app, that calls AAM to launch the packaged app).

If you're unpackaged then AAM isn't relevant. It takes as input an ApplicationUserModelID (aka AppUserModelID aka AUMID aka application identity) per your manifested definition in your appxmanifest.xml. But that only exists if you're packaged. Unpackaged apps have no appxmanifest.xml and no package or application identity, thus no AUMID and thus AAM isn't relevant. CreateProcess, ShellExecute, desktop shortcuts (.LNK) and all the other classic Win32 mechanisms apply.

@rcohn
Copy link

rcohn commented Feb 23, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants