microsoft / microsoft/microsoft-ui-xaml

In C++ `FindName` wont reload an object that has been `UnloadObject`ed

Open
#10,179 2 comments 1 reaction 0 assignees View on GitHub
area-CoreFramework area-DevInternal bug team-Core
Dominant language
C++
Stars
8.4k
Forks
942
Avg merge
2d 7h
Merged PRs (30d)
105

Description

### Describe the bug

This doesn't happen in C#

This also happens if we replace the call to `UnloadObject` with `myStackPanel.Children().ReplaceAll({});`. This is similar to https://github.com/microsoft/microsoft-ui-xaml/issues/10176

### Steps to reproduce the bug

```xaml


Click Me

```

```cpp
void MainWindow::myButton_Click(IInspectable const&, RoutedEventArgs const&)
{
UnloadObject(myButton());
winrt::check_bool(!myButton());
auto r = myStackPanel().FindName(L"myButton");
winrt::check_bool(!r); // wrong
winrt::check_bool(!myButton()); // wrong
}
```

```c#
private void myButton_Click(object sender, RoutedEventArgs e)
{
UnloadObject(myButton);
Debug.Assert(myButton == null);
var r = myStackPanel.FindName("myButton");
Debug.Assert(r != null); // good
Debug.Assert(myButton != null); // good
}
```

### NuGet package version

WinUI 3 - Windows App SDK 1.6.3: 1.6.241114003

### Windows version

Windows 11 (21H2): Build 22000

### Additional context

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the C++ sample using UnloadObject(myButton()) and myStackPanel().FindName(L"myButton"), then compare it with the C# behavior shown in the issue. Investigate the UnloadObject and FindName paths, including the ReplaceAll variant; done means the C++ lookup and generated myButton reference behave as expected after unloading.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, csharp
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.