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

Error & crash when showing ContentDialog without XamlRoot #3678

Open
mrlacey opened this issue Nov 23, 2020 · 6 comments
Open

Error & crash when showing ContentDialog without XamlRoot #3678

mrlacey opened this issue Nov 23, 2020 · 6 comments
Labels
area-Dialogs bug Something isn't working product-winui3 WinUI 3 issues team-Controls Issue for the Controls team

Comments

@mrlacey
Copy link
Contributor

mrlacey commented Nov 23, 2020

Describe the bug

ArgumentException is thrown when attempting to open a ContentDialog in a WinUI3 Desktop app when the XamlRoot is not set.
X-Ref docs

Steps to reproduce the bug

  1. Create a new blank WinUI3 Desktop app
  2. Add this class
public sealed partial class MyCustomDialog : ContentDialog
{
    public MyCustomDialog()
    {
        this.InitializeComponent();
    }
}
  1. With this XAML
<ContentDialog
    x:Class="App206.MyCustomDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="TITLE"
    PrimaryButtonText="Button1"
    SecondaryButtonText="Button2">

    <Grid>
        <TextBlock>hello</TextBlock>
    </Grid>
</ContentDialog>
  1. Change myButton_Click in MainPage.xaml.cs to be:
private async void myButton_Click(object sender, RoutedEventArgs e)
{
    var dialog = new MyCustomDialog();
    await dialog.ShowAsync();
}
  1. Run the app and click the button.
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.global::Microsoft.UI.Xaml.Controls.IContentDialog.ShowAsync()
   at Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync()
   at App206.MainWindow.<myButton_Click>d__1.MoveNext() in C:\Users\matt\source\repos\App206\App206\App206\MainWindow.xaml.cs:line 35

Expected behavior

The dialog will not be be shown because there is no XamlRoot but:

  • The app should not crash.
    and/or
  • There should be a more descriptive error message displayed indicating the issue.

Screenshots

Version Info

NuGet package version:
Microsoft.WinUI 3.0.0-preview3.201113.0

Windows app type:

UWP Win32
No Yes
Windows 10 version Saw the problem?
Insider Build (20175.1000) Yes
May 2020 Update (19041) Yes
November 2019 Update (18363)
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
Xbox
Surface Hub
IoT

Additional context

This works without issue in a UWP app (WinUI2 and 3)

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 23, 2020
@mrlacey
Copy link
Contributor Author

mrlacey commented Nov 23, 2020

X-Ref #1679 which discusses other ContentDialog related issues and possible improvements.

@sylveon
Copy link
Contributor

sylveon commented Nov 23, 2020

I believe you're forgetting to set the XamlRoot

@mrlacey
Copy link
Contributor Author

mrlacey commented Nov 23, 2020

I believe you're forgetting to set the XamlRoot

Yes, this was the issue.

Will update the OP to reflect the need not to crash and provide a more descriptive error message.

@mrlacey mrlacey changed the title Error when showing ContentDialog in desktop app Error when showing ContentDialog without XamlRoot Nov 23, 2020
@ranjeshj ranjeshj added product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Nov 24, 2020
@bpulliam bpulliam added the team-Controls Issue for the Controls team label Oct 30, 2022
@github-actions
Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@mrlacey mrlacey changed the title Error when showing ContentDialog without XamlRoot Error & crash when showing ContentDialog without XamlRoot Jul 31, 2023
@mrlacey
Copy link
Contributor Author

mrlacey commented Jul 31, 2023

At the very least this needs a more helpful error message.

This gives no clue as to the cause and so doesn't help solve the cause of the crash.

System.ArgumentException - Message=Value does not fall within the expected range.

@nickrandolph
Copy link

Let's bump the priority on this issue - it's seriously nuts that developers have to set xamlroot on a dialog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Dialogs bug Something isn't working product-winui3 WinUI 3 issues team-Controls Issue for the Controls team
Projects
None yet
Development

No branches or pull requests

7 participants