Fall back to Window.Title
if GetWindowText
fails
#7345
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.
This is an attempt to recover from badly-behaving Windows message hooks that may change the last error during message processing.
Fixes #7344
Fixes #4181
Description
UnsafeNativeMethods.GetWindowText
may throw if badly-behaving Windows message hooks are installed on the system, or potentially for other reasons. This can crash a WPF application.Instead of crashing, we now ignore the exception and try to fall back to using
Window.Title
, which should contain the same text.Customer Impact
WPF applications can crash unpredictably. It may be possible for customers to work around it with more P/Invoke code: #6026 (comment)
Having a fix in WPF itself would be simpler for most customers.
Regression
No.
Testing
Will ship in a consumer application and monitor user crash reports.
Risk
Legitimate failures of GetWindowText (too short a buffer? something else?) might incorrectly be ignored. However, if
Window.Title
is used as a fallback, the risk seems minimal.Microsoft Reviewers: Open in CodeFlow