question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

AppWindow.GetFromWindowId crashes in WinUI3 desktop application in unpackaged mode.

See original GitHub issue

Describe the bug

  • NuGet package version: Windows App SDK 1.0.0 (stable)
  • VisualStudio 2022. 17.0.1
  • x64

Steps to reproduce the bug

  1. Create “Blank App, Packaged (WinUI 3 in Desktop)” project.
  2. Delete “Package.appxmanifest”.
  3. Add <WindowsPackageType>None</WindowsPackageType> to the property group in the project.
  4. Add this code.
public MainWindow()
{
    this.InitializeComponent();

    IntPtr hWnd = WinRT.Interop.WindowNative.GetWindowHandle(this);
    WindowId myWndId = Microsoft.UI.Win32Interop.GetWindowIdFromWindow(hWnd);
    AppWindow aw = AppWindow.GetFromWindowId(myWndId);
}
  1. Run the application.
Exception thrown: 'System.Reflection.TargetInvocationException' in System.Private.CoreLib.dll
Exception has been thrown by the target of an invocation.

stack trace.

   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean wrapExceptions, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& hasNoDefaultCtor)
   at System.RuntimeType.CreateInstanceDefaultCtorSlow(Boolean publicOnly, Boolean wrapExceptions, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, Boolean wrapExceptions)
   at System.Activator.CreateInstance[T]()
   at WinRT.WeakLazy`1.get_Value()
   at Microsoft.UI.Windowing.AppWindow._IAppWindowStatics.get_Instance()
   at Microsoft.UI.Windowing.AppWindow.GetFromWindowId(WindowId windowId)
   at ModuleHub.MainWindow..ctor() in C:\\k4\\ModuleHub\\ModuleHub\\MainWindow.xaml.cs:line 42"	string

Inner exception.

SEHException: External component has thrown an exception.

stack trace.

   at WinRT.Platform.RoGetActivationFactory(IntPtr runtimeClassId, Guid& iid, IntPtr* factory)
   at WinRT.WinrtModule.GetActivationFactory(IntPtr hstrRuntimeClassId)
   at WinRT.WinrtModule.GetActivationFactory(String runtimeClassId)
   at WinRT.BaseActivationFactory..ctor(String typeNamespace, String typeFullName)
   at Microsoft.UI.Windowing.AppWindow._IAppWindowStatics..ctor()"	string

Expected behavior

No response

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 0.8: 0.8.0 (If you’re seeing your issue in older previews of WinUI 3, please try this release)

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

May 2020 Update (19041)

Additional context

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:16 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Balkothcommented, Jan 14, 2022

There should not be any hacks needed to make a winui3 app run on an already supported platform. Sadly this 1.0 version feels rushed, nowhere near production viable.

1reaction
castorixcommented, Nov 20, 2021

I had signaled it in the WindowsAppSDK forum, but after some tests, I found that the bug is fixed by adding

 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1"> 
        <application>
			<!-- Windows 10 -->
			<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>           
        </application> 
    </compatibility>

in the app.manifest

Read more comments on GitHub >

github_iconTop Results From Across the Web

WinUI 3 App Runs on Development Machine, Crashes ...
I have a WinUI3/Windows App executable which runs fine on my development machine. After it's signed it can be installed on the development ......
Read more >
What's New in Windows App SDK 1.1
The Windows App SDK is the starting point for building and shipping Windows desktop apps (spanning C++ and .NET) with WinUI 3 controls...
Read more >
WinUI 3 app crashed when deployed to the store
Since I deploy my app to the store I think it goes under packaged. As far as I can see this issue only...
Read more >
Control the Window of your WinForms, WPF or Windows UI ...
In this post we're going to look at what the Windows App Sdk brings to the table in ... The next thing you'll...
Read more >
Is WinUI really production ready? : r/dotnet
I'm interested in any real world learnings about WinUI3. ... beginning of development, there were a lot of unexpected application crashes.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found