The ContentDialog.ShowAsync throws the ArgumentException
See original GitHub issueDescribe the bug
Hi, the ShowAsync throws the ArgumentException Value does not fall within the expected range.
Steps to reproduce the bug
public sealed partial class MainWindow : Window {
public MainWindow() {
this.InitializeComponent();
}
private async void myButton_Click(object sender, RoutedEventArgs e) {
var dlg = new ContentDialog() {
Title = "Result Dialog",
Content = "Test",
CloseButtonText = "OK"
};
await dlg.ShowAsync();
}
}
<StackPanel x:Name="stackPanel" Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="myButton" Click="myButton_Click">Click Me</Button>
</StackPanel>
Expected behavior
Screenshots
Version Info
NuGet package version:
[WinUI 3 - Project Reunion 0.5: 0.5.5]
Windows app type:
UWP | Win32 |
---|---|
Yes |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
October 2020 Update (19042) | Yes |
May 2020 Update (19041) | |
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
WinRT.Runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr = -2147024809) Unknown
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Controls.IContentDialog.Microsoft.UI.Xaml.Controls.IContentDialog.ShowAsync() Unknown
Microsoft.WinUI.dll!Microsoft.UI.Xaml.Controls.ContentDialog.ShowAsync() Unknown
> App2.dll!App2.MainWindow.myButton_Click(object sender = {Microsoft.UI.Xaml.Controls.Button}, Microsoft.UI.Xaml.RoutedEventArgs e = {Microsoft.UI.Xaml.RoutedEventArgs}) Line 34 C#
[Lightweight Function]
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke.AnonymousMethod__0(Microsoft.UI.Xaml.RoutedEventHandler invoke = {Method = <Internal Error evaluating expression>}) Unknown
WinRT.Runtime.dll!WinRT.ComWrappersSupport.MarshalDelegateInvoke<Microsoft.UI.Xaml.RoutedEventHandler>(System.IntPtr thisPtr = 0x186fbdac, System.Action<Microsoft.UI.Xaml.RoutedEventHandler> invoke = {Method = {System.Reflection.RuntimeMethodInfo}}) Unknown
Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.RoutedEventHandler.Do_Abi_Invoke(System.IntPtr thisPtr = 0x186fbdac, System.IntPtr sender = 0x100a23ec, System.IntPtr e = 0x1a430628) Unknown
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
'Value does not fall within the expected range.' on Content ...
I'm triyng to make a login system in my UWP (WinUI3) app and when I try to lauch de Login Content Dialog it...
Read more >ContentDialog.ShowAsync Method - Windows
Begins an asynchronous operation to show the dialog with the specified placement.
Read more >How do I use contentdialog in winui3
Current.Content.XamlRoot, }; await infoDialog.ShowAsync(); } I'm tying to use it like: C#. DisplayInfoDialog("Fail", "It fails because");
Read more >WinUI 3 的對話視窗ContentDialog 示範 - Ruyut 鹿遊
ArgumentException : Value does not fall within the expected range. at WinRT. ... ShowAsync(IObjectReference _obj) at Microsoft.UI.Xaml.
Read more >WinUI 3.0 (Project Reunion 0.5) で ContentDialog を使う方法
Exception thrown: 'System.ArgumentException' in WinRT.Runtime.dll WinRT information: This element is already associated with a XamlRoot, it ...
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
@sylveon is correct, the best work around it to parent the content dialog somewhere in your xaml tree, preferably from markup.
An alternative is putting the ContentDialog directly in the XAML code, then the XamlRoot is automatically assigned and as a bonus localization is easier since resw just works.