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.

Unhandled exception on popup open

See original GitHub issue

Describe the bug

Such a code causes an unhandled exception

image

Steps to reproduce the bug

  1. Create a blank WinUI app for desktop
  2. Add the following code in MainWindow constructor after InitializeComponent.
        var p = new Popup();
        p.Child = new TextBlock() { Text = "Text" };
        p.IsOpen = true;
  1. Run application

Version Info

Windows 10 1903 (OS Build 18362.1082)

NuGet package version:

WinUI 3.0.0-preview2.200713.0

Windows app type:

UWP Win32
Yes
Device form factor Saw the problem?
Desktop Yes

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
codendonecommented, Nov 25, 2020

The error message shown in the output window is “explaining” the error, but we should definitely make some improvements to better expose the error (rather than just seeing the E_UNEXPECTED message in the exception dialog), better explain what needs to be done, and better document this issue.

The problem is that this is a parentless popup, so XAML doesn’t know which window to show the popup for. (And it complains even when there is only one to prevent weird behavior of having code stop working when there is more than one window.) There are two possible fixes to this: (1) add the Popup in the Children list of some other element, or (2) set the XamlRoot property to explicitly state what the popup belongs to.

Option (2) provides a trivial fix in your example by adding the second line here:

            var p = new Popup();
            p.XamlRoot = this.Content.XamlRoot;
            p.Child = new TextBlock() { Text = "Popup Text" };
            p.IsOpen = true;

Note: The XamlRoot needs to be set before setting the popup to IsOpen=true.

0reactions
github-actions[bot]commented, Jul 29, 2023

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Exception unhandled popup
Open the Exception settings window (Under Debugger->Windows) and add a checkbox next to "Common language exceptions". This now might show some ...
Read more >
How to Fix the "Unhandled Exception Has Occurred in ...
If your apps have issues running, here's how to fix unhandled exceptions on Windows.
Read more >
Unhandled exception popup font - Developer Community
I got it. The exception popup uses Environment font. But text in it uses OTHER rendering than solution explorer and ALL other VS2017...
Read more >
Manage exceptions with the debugger in Visual Studio
In the Exception Settings window, open the shortcut menu by right-clicking a column label, and then select Show Columns > Additional Actions. ( ......
Read more >
Unhandled exception popup when try to open Ranorex ...
I try to edit my old recording. When click save, it pop up exception "Error while saving" . After a few times click...
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