Port UpdatePeer fix from 4.8 #4995
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Addresses Issue #4992
This is a port of a servicing fix in .NET 4.7-4.8.
Description
The root cause is calling peer.InvalidatePeer(), which schedules an asynchronous call to peer.UpdatePeer(), then removing the peer from the automation tree before the async call happens. UpdatePeer calls several methods that look for context in the automation tree and throw ElementNotAvailableException if the context can't be found.
This is similar to a bug fixed 3 years ago. The differences are
this bug: peer represents a data item
this bug: peer invalidated because GridViewColumnCollection changed
There are two factors in the customer's app that contribute to the crash, both having to do with the grouped ListView control:
Theme changes happen when you reconnect to RDP, but the bug also repros if the end-user simply changes the theme, e.g. by turning HighContrast on or off.
The overrides in ItemAutomationPeer that throw ElementNotAvailableException check explicitly for GridViewItemAutomationPeer and bypass the throw. This explains why the crash doesn't occur in apps that use the built-in ListView/GridView and peers, even if they change the column collection and remove items in the same way the customer's app does.
The fix is to extend the mechanism we introduced to fix the older bug - a check to ignore the async call to UpdatePeer if the peer has left the automation tree - to handle the data-item peer case.
Customer Impact
Crash when reconnecting to RDP.
Regression
No.
Testing
Ad-hoc around customer scenario.
Standard regression testing.
Risk
Low. Port of a .NETFx servicing fix released earlier this year.