ContentDialog fails to display WinUI 3 Preview 1 and .NET 5 Desktop
See original GitHub issueDescribe the bug While trying out WinUI3 and .NET 5 desktop app, I tried to display a ContentDialog both in code and via a XAML definition. In both circumstances I received the the following exception:
System.ArgumentException
HResult=0x80070057
Message=Value does not fall within the expected range.
Source=WinRT.Runtime
StackTrace:
at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)
at ABI.Microsoft.UI.Xaml.Controls.IContentDialog.ShowAsync()
at Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync()
at N5UI3Test.MainWindow.<myButton_Click>d__1.MoveNext() in D:\D-Repos\N5UI3Test\N5UI3Test\N5UI3Test\MainWindow.xaml.cs:line 42
Steps to reproduce the bug
Steps to reproduce the behavior:
-
Create new Blank App, Packaged (WinUI in Desktop) app
-
Open MainWindow.xaml.cs.
-
Update the myButton_Click method to the following:
private async void myButton_Click(object sender, RoutedEventArgs e) { myButton.Content = "Clicked"; var cd = new ContentDialog { Title = "Button Clicker!", Content = "You clicked the button!", CloseButtonText = "Ok" }; var result = await cd.ShowAsync(); }
-
Run the app
-
Click the Click Me button and observe the exception.
Expected behavior
I expect to see the ContentDialog displayed.
Screenshots
Version Info
Windows 10 Version 1909 (18363.836) Microsoft Visual Studio Enterprise 2019 Preview Version 16.7.0 Preview 1.0 Desktop PC 2x 4K monitors Microsoft.NETCore.App 5.0.0-preview.4.20251.6
NuGet package version: Microsoft.WinUI 3.0.0-preview1.200515.3
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
November 2019 Update (18363) | Yes |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Mobile | |
Xbox | |
Surface Hub | |
IoT |
Additional context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:9
- Comments:17 (6 by maintainers)
Top GitHub Comments
Confirmed the above.
I updated the myButton_Click method to:
The ContentDialog is then displayed as expected.
This issue still exists in WinUI3, with the same vague error message. And agreeing with what others have written, documentation for WinUI is sparse. Also, with the different frameworks now it’s hard to find the right way for the framework you’re using. Coming from WPF but not having used UWP before, it’s sometimes unclear where to look: WinUI? WinRT? UWP? Some things from WPF work in WinUI but others don’t, so what’s the alternative?