Completed
Last Updated: 18 Feb 2022 11:24 by ADMIN
Release R1 2022 SP1
Simon
Created on: 07 Feb 2022 09:03
Category: AutoCompleteBox
Type: Bug Report
0
AutoCompleteBox: InvalidOperationException in combination with RadTabControl/RadDocking

Hi,

unfortunately, I have yet another bug report regarding the RadAutoCompleteBox. This time, it looks like a regression introduced in one of the last two Releases of Ui for WPF as we recently upgraded from 2021.3.914.45 to 2022.1.117.45 and the crash only happens with the newer version.

In one of our applications we get an InvalidOperationException: "Cannot modify the logical children for this node at this time because a tree walk is in progress."  when setting RadPane.Hidden = true for a Pane that contains at least one RadAutoCompleteBox.

In the attached text file you can find the full stack trace. I noticed that RadPaneGroup inherits from RadTabControl so maybe the regression was caused by some of the changes in my other report regarding AutoCompleteBoxes in TabControls. The pattern seems to be the same at least: The crash only seems to occur if you type into the AutoCompleteBox and select an item from the DropDown.

Crash occurs if:

  • You type into the box, select an item from the Dropdown and then switch to another module (see attached gif).

Crash does not occur if:

  • The AutoCompleteBox is not touched at all
  • The bound properties are only changed by the ViewModel
  • You type into the box to trigger the Dropdown but do NOT select an item

 

As a side note:

While debugging the issue I noticed that RadNavigationView seems to have an exception handler somewhere that silently swallows this exception, causing really strange behavior in the RadDocking control. I also attached a gif for this behavior (-UI.gif).

 	Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadNavigationView.OnSelectionChangerSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e = {System.Windows.Controls.SelectionChangedEventArgs})	Unknown
 	Telerik.Windows.Controls.dll!Telerik.Windows.Controls.SelectionChanger<System.__Canon>.InvokeSelectionChangedEvent(System.Windows.Controls.SelectionChangedEventArgs e)	Unknown
 	Telerik.Windows.Controls.dll!Telerik.Windows.Controls.SelectionChanger<System.__Canon>.End()	Unknown
 	Telerik.Windows.Controls.dll!Telerik.Windows.Controls.SelectionChanger<object>.AddJustThis(object item)	Unknown
>	Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadNavigationView.UpdateSelection(System.Windows.Controls.Primitives.Selector targetSelector, object item)	Unknown
 	Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadNavigationView.NotifyNavigationViewItemClick(Telerik.Windows.Controls.RadNavigationViewItem container)	Unknown
 	Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadNavigationViewItem.OnClickInternal()	Unknown
 	Telerik.Windows.Controls.Navigation.dll!Telerik.Windows.Controls.RadNavigationViewItem.OnClick()	Unknown
 	PresentationFramework.dll!System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e)	Unknown

Regards
Simon Müller
Hofmann Fördertechnik GmbH

 

7 comments
ADMIN
Petar Mladenov
Posted on: 17 Feb 2022 16:09

Hi Simon,

Thank you for the last isolated project. We managed to reproduce the issue and we will add a fix for it in the upcoming service pack next week.

Regards,
Petar Mladenov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Simon
Posted on: 16 Feb 2022 10:04

Hi Petar,

I was finally able to spend some time on creating a repro project. I reduced our application to only include parts of the navigation code and the AutoCompleteBox in a simple view. To show the difference between the two Ui for WPF versions, I attached two solutions which are identical except for the referenced library version. I hope this is of some help to identifiy the issue.

Best regards
Simon Müller

 

ADMIN
Petar Mladenov
Posted on: 14 Feb 2022 15:20

Hi Simon,

Thank you for these details. We cannot see a direct relation between the mentioned fix and the exception you report. However, it can be 100% verified if we have the exception reproducible and test with code versions before and after the fix (which is easy because it is a small portion of code no coupled with other features / bug fixes). So if the proposed workaround does not work in your case / is not applicable I encourage you to :
  - ether isolate your business application to a subset that can be send to us and reproduces the issue
 -  make changes in the isolation you have tried so that they add code that is needed to mimic the issue in the business application

Regards,
Petar Mladenov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Simon
Posted on: 11 Feb 2022 07:44

Hello Petar,

thank you for your quick response! I was not yet able to test the workaround you mentioned but will do so and report back after. However, I wanted to get back to you on the regression topic as quick as possible:

Is there any chance during your upgrade you have switched from XAML to no-XAML binaries

We are actually using the NoXaml binaries already. I can't think of any place where we would be using the Xaml ones. So I don't think any change like this could have happened.

or you have added an additional nesting in XAML, or additional Styles that apply to docking elements

This is also not the case. In fact, the View hasn't gotten any changes since October of last year.

Fortunately, I did the upgrade in a separate git commit so I was able to compare both versions. And indeed, when comparing the revision before the upgrade to 2022.1.117 with the revision after the upgrade the crash is only happening with the new version. I attached the .patch for the upgrade commit so you can also check the changes that happened.

What made me think of a regression initially is the bugfix "Loading databound AutoCompleteBox in TabControl in no-xaml binaries scenario with FluentTheme throws NullReferenceException" from the release log (which I believe is actually the fix for another problem I reported here). The scenario is pretty much the same as in this case (except that the RadTabControl is now indirectly added to the tree through the RadPaneGroup). So maybe that bug fix for the loading introduced a change that now causes this crash when unloading the control?

 

Regards
Simon Müller

 

ADMIN
Petar Mladenov
Posted on: 10 Feb 2022 16:48

Hello Simon,

And thank you for the additional details. I played with your project but could not reproduce the mentioned issue. However, looking in our history we have seen a few similar reports with similar stack trace. They have in common the following :
   - Pane is auto assigned with DataContext (meaning the Framework make it inherit from the parent element)

   - RadDocking is in Compelx UI with several nested controls , one of the reports shows Docking nested in Docking

   - when pane is hidden / unloaded (via IsHiddenBinding), datacontext is lost and Framework tries to unload the pane from the group but the exception says a tree walk (bindings evaluation) is is progress which is not allowed.

You can check for example this thread.
We haven't log this as a bug since there is a solution applicable to this scenario (as proposed in the forum - redirect the DataContext in XAML to the datacontext of other element this way preventing the automatic inheritance). Also its with high risk to introduce similar code internally in RadDocking as this cases are rare but its likely to break many more existing clients with risky code which detaches datacontext in certain unload / datacontext changing scenarios. At least this could break an application logic already implemented.

Could you please try the suggested workaround in your business application and let us know if it is applicable ? Also, it is of high priority for us to double check this is not a regression introduced on our side as you suggested in your first post. We look at the changes in Docking /AutoComplete during the mentioned R3/R1 2022 period and could not find anything related. Is there any chance during your upgrade you have switched from XAML to no-XAML binaries or you have added an additional nesting in XAML, or additional Styles that apply to docking elements ?

Regards,
Petar Mladenov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Simon
Posted on: 10 Feb 2022 12:11

Hello Petar,

thank you for your answer! I will try to answer your questions one by one.


> I've managed to reproduce a NUllReferenceException but with different stack trace.  [...] however, I don't believe it is related to your exception having look at your stack trace.

Indeed I think that the issue you found is not related to the issue we are encountering. We even have AutomationManager.AutomationMode = AutomationMode.Disabled; set in our App's constructor since the automation peers gave us issues in the past.


> can you send us your XAML so that we can get a picture of how is your UI configured, how are the controls nested into one another and how are they loaded - via Items properties or via MVVM with ContentTemplate /Selector properties.

Our application is quite large so I can't send you the full xaml code unfortunately. However, I will try to give you an overview of our navigation system and the important parts of the xaml code. I will also attach a small project where I tried to reproduce the issue (unfortunately I wasn't able to reproduce though...)

Regarding MVVM: Yes, we are using MVVM in most places. The only exception is our navigation code which uses Code-Behind of the MainWindow to add/remove/hide/activate RadPanes to/from our main RadDocking container (or rather the RadSplitContainer within it...).

<Grid Grid.Row="1">
<!-- Main Content -->

    <telerik:RadDocking
        x:Name="RadDocking"
        HasDocumentHost="False"
        RetainPaneSizeMode="DockingAndFloating"
        IsRestricted="True"
        Close="RadDocking_Close"
        BorderBrush="Transparent">
        <telerik:RadSplitContainer x:Name="MainContentContainer" />
    </telerik:RadDocking>
</Grid>

  • All our modules are ViewModels that are set as the content of a RadPane and displayed via DataTemplates that directly map to UserControls. So in order to display "MainView" we would create a RadPane and set its Content and DataContext to an instance of MainViewModel. This implicitly loads MainView in the RadPane through a DataTemplate.
  • One of the failing AutoCompleteBoxes is located inside the UserControl with some Grids and a ScrollViewer around the whole view. But not really a lot more (at least going up the tree).
     It is defined as follows:

    <telerik:RadAutoCompleteBox x:Name="CustomerNumberAutocompleteBox"
                                Grid.Row="1"
                                Grid.Column="1"
                                Margin="2,2,10,2"
                                VerticalAlignment="Center"
                                AutoCompleteMode="SuggestAppend"
                                DisplayMemberPath="CustomerNameAndNumber"
                                DropDownWidth="{Binding ElementName=CustomerNumberAutocompleteBox, Path=ActualWidth}"
                                IsEnabled="{Binding CustomerNameEnabled}"
                                ItemsSource="{Binding ViewCustomerSearchBusinessObjects, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                SearchText="{Binding ViewCustomerNumberSearchText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                SelectedItem="{Binding ViewSelectedCustomerBusinessObject, ValidatesOnDataErrors=True, NotifyOnValidationError=True, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                                SelectionMode="Single"
                                TextSearchMode="Contains"
                                TextSearchPath="CustomerNumber"
                                WatermarkContent="{StaticResource Loc.CustomerNumber}">
        <i:Interaction.Behaviors>
            <behaviors:BubbleScrollBehavior /> <!-- Fix for scrolling being blocked if the mouse is over the control -->
        </i:Interaction.Behaviors>
    </telerik:RadAutoCompleteBox>

 

> are you able to isolate/comment the navigation view and still reproduce the exception  ?

Yes, I just commented the RadNavigationView from the XAML and the exception was still happening as before.

 

Additional info

  • I just noticed that the issue seems to only happen for the "top" level of our module: By using the buttons in the bottom left in the initial gifs I sent you, the user is able to add positions Which are located inside a simple ItemsControl. Those positions also contain RadAutoCompleteBoxes. However, those don't seem to have the problem. See the gif I attached to this post.

  • The issue also does not happen if the AutoCompleteBox's SelectionMode is set to "Multiple".

  • I also did some further debugging and tried to get as much information out of the stack trace as possible. Unfortunately, all the dependencies are optimized so there was not much to get there:
    • line 7: The name of the changed property is "Content"
    • line 11 - 14: all the style stuff involves a ContentPresenter
    • line 51: The FrameWorkElement is the RadAutoCompleteBox. At this point its DataContext is null, ItemsSource is {object[0]}, SearchText is "" and SelectedItem is null
    • line 56: The BindingExpression has the Path "ViewSelectedCustomerBusinessObject" (so its for the SelectedItem)
    • line 59: The property that's invalidated seems to be "DataContext" of the RadAutoCompleteBox (makes sense since the next call goes to OnDataContextChanged())

So it looks like deactivating the RadPane starts a tree walk which sets the AutoCompleteBox's DataContext to null which in turn sets the SelectedItem to null, causing the Content of the AutoCompleteBox to be re-rendered (which must not happen since a tree walk is in progress).

 

Regards
Simon Müller

ADMIN
Petar Mladenov
Posted on: 09 Feb 2022 16:08

Hello Simon,

Thank you for this report. With similar steps and RadTabControl configured like so:

     <telerik:RadTabControl ItemsSource="{Binding Pages}" x:Name="tabControl">
            <telerik:RadTabControl.ContentTemplate>
                <DataTemplate DataType="local:TabPageViewModel">
                    <Grid>
                    <telerik:RadAutoCompleteBox ItemsSource="{Binding SelectionItems}"
                                                SelectedItem="{Binding Item, Mode=TwoWay}"/>
                        <Button VerticalAlignment="Bottom" Content="remove" Click="Button_Click" />
                    </Grid>
                </DataTemplate>
            </telerik:RadTabControl.ContentTemplate>
        </telerik:RadTabControl>

I've managed to reproduce a NUllReferenceException but with different stack trace.

Its root comes from an AutomationPeer code which fires under certain conditions (for example some windows service or program which forces creation of AutomationPeers). We will certainly address it in future versions, however, I don't believe it is related to your exception having look at your stack trace. Also you indicate you indicate a regression which is not the case in my scenario. That is why I wanted to ask you for additional details:

    -- can you send us your XAML so that we can get a picture of how is your UI configured, how are the controls nested into one another and how are they loaded - via Items properties or via MVVM with ContentTemplate /Selector properties.
    -- are you able to isolate/comment the navigation view and still reproduce the exception  ?

Regards,
Petar Mladenov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.