AppWindow.GetFromWindowId crashes in WinUI3 desktop application in unpackaged mode.
See original GitHub issueDescribe the bug
- NuGet package version: Windows App SDK 1.0.0 (stable)
- VisualStudio 2022. 17.0.1
- x64
Steps to reproduce the bug
- Create “Blank App, Packaged (WinUI 3 in Desktop)” project.
- Delete “Package.appxmanifest”.
- Add
<WindowsPackageType>None</WindowsPackageType>
to the property group in the project. - 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);
}
- 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:
- Created 2 years ago
- Comments:16 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
I had signaled it in the WindowsAppSDK forum, but after some tests, I found that the bug is fixed by adding
in the app.manifest