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.

ContentDialog fails to display WinUI 3 Preview 1 and .NET 5 Desktop

See original GitHub issue

Describe 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:

  1. Create new Blank App, Packaged (WinUI in Desktop) app

  2. Open MainWindow.xaml.cs.

  3. 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();
    }
    
  4. Run the app

  5. Click the Click Me button and observe the exception.

Expected behavior

I expect to see the ContentDialog displayed.

Screenshots

image

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:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:17 (6 by maintainers)

github_iconTop GitHub Comments

23reactions
darenmcommented, May 21, 2020

Confirmed the above.

I updated the myButton_Click method to:

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"
    };

    cd.XamlRoot = this.Content.XamlRoot;
    var result = await cd.ShowAsync();

    //var cd = new ContentDialogExample();
    //await cd.ShowAsync();
}

The ContentDialog is then displayed as expected.

12reactions
dedaap72commented, Nov 26, 2021

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

WinUI 3 ContentDialog and icons : r/dotnet
I'm trying to migrate MessageBoxes and TaskDialogs to WinUI 3's ContentDialog. One sticking point is that message boxes have an icon (e.g., ...
Read more >
Why is my ContentDialog in WinUI 3 displaying empty even ...
Seems pretty basic, right? So why is my dialog appearing like this with no TextBox in it? It doesn't matter what UI controls...
Read more >
How do I use contentdialog in winui3
I have built an unpackaged app with .Net6 and WinUI3. Before launching the Main Window, i do some checks and API Requests. If...
Read more >
C# WinUI 3 Desktop Application Issue with ContentDialog ...
I am building a C# WinUI 3 desktop app running on Windows 10. I want to use a contentdialog to display error messages....
Read more >
WinUI 3 Preview 4 is available
Crash when using NavigationView control with multiple windows on the same thread; Accessibility Issue: Show focus rect on WinUI desktop app ...
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