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.

TreeView - AccessViolationException with SelectedItem

See original GitHub issue

The TreeView still throws an AccessViolationException, in Microsoft.UI.Xaml 2.5.0-prerelease.200708003 despite issues #2405 and #2303 being reported as closed.

Steps to reproduce the bug Here is a sample MainPage.xaml

<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
    x:Class="App1.MainPage">

    <StackPanel>
        <muxc:TreeView ItemsSource="{x:Bind Mode=OneWay, Path=List}"
                       SelectedItem="{x:Bind SelectedItem}"/>
    </StackPanel>
</Page>

And the code-behind MainPage.xaml.cs

namespace App1
{
    public sealed partial class MainPage : Page
    {
        private ObservableCollection<string> List { get; set; } = new ObservableCollection<string>()
        {
            "Item 1",
            "Item 2",
            "Item 3",
        };

        private string SelectedItem { get; set; }

        public MainPage()
        {
            this.InitializeComponent();
            SelectedItem = List[1];
        }
    }
}

Steps to reproduce the behavior:

  1. Launch App1.
  2. Observe it crash with the following exception:
An unhandled exception of type 'System.AccessViolationException' occurred in App1.exe
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

The program '[9000] App1.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

Expected behavior The app doesn’t crash and opens with the Item 2 selected.

Version Info

NuGet package version: Microsoft.UI.Xaml 2.5.0-prerelease.200708003

Windows app type:

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

Additional context It looks like nothing has been done to specifically fix the previous issues #2405 and #2303, which were assumed to have been fixed by other changes.

This crash is pretty bad, we cannot catch the exception, and it’s critical to get to the bottom of those issues and have them fixed properly.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
chingucodingcommented, Aug 14, 2020

The issues #2405 and #2303 were fixed by the switch away from a regular property to a dependency property for SelectedItem, as those both hit an issue where the tracker_ref ended up in a bad state.

This bug is different to the other bugs, but is a bug none the less. @ranjeshj I would like to look into this issue.

0reactions
sis2004commented, Sep 24, 2020

Thanks, I have done a cursory test with the new release, and the issue didn’t manifest itself. I’ll let you know if we see this issue again.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TreeView - AccessViolationException on remove an item
I can't repro the AccessViolationException either, the app loads 3 items in the treeview. The only crashes that happen is the crash when ......
Read more >
WinForms TreeView AccessViolationException
At one point, I have one of the subforms change the IsSelectable property for another, then call UpdateFormSelection. The second subform appears ...
Read more >
WPF: Not able to get TreeViewItem from the SelectedItem
Here is how I made it work. Set the ItemsContainerStyle of the TreeView such that a Handler is invoked whenever a TreeViewItem is...
Read more >
AccessViolationException in Finalizer when using remote ...
AccessViolationException in Finalizer when using remote desktop and rendering to a window.
Read more >
[Solved] Access Violation Exception was unhandled
Access Violation Error, I have tried in Windows XP PC and I don't get any ... TreeView view) { string query = "select...
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