Skip to content

Adding static constructor to StyleHelper class#7295

Merged
dipeshmsft merged 1 commit intomainfrom
fix/styleHelper
Dec 28, 2022
Merged

Adding static constructor to StyleHelper class#7295
dipeshmsft merged 1 commit intomainfrom
fix/styleHelper

Conversation

@Kuldeep-MS
Copy link
Contributor

@Kuldeep-MS Kuldeep-MS commented Nov 17, 2022

Fixes #7205
Fixes #7291

Description

Adding static constructor to StyleHelper class to do the required initialization i.e. registering the "alternative Expression storage". Also, adding check to "RegisterAlternateExpressionStorage" function to avoid re-registration being called.

Customer Impact

An attempt to call the BindingOperations.GetBindingExpression method in .NET 7.0 leads to Null Reference Exception.

Regression

Yes

Testing

In progress

Risk

NA

Microsoft Reviewers: Open in CodeFlow

@Kuldeep-MS Kuldeep-MS requested a review from a team as a code owner November 17, 2022 09:15
@ghost ghost assigned Kuldeep-MS Nov 17, 2022
@ghost ghost added the PR metadata: Label to tag PRs, to facilitate with triage label Nov 17, 2022
@ghost ghost requested review from dipeshmsft and singhashish-wpf November 17, 2022 09:15
@Kuldeep-MS Kuldeep-MS changed the title fix(StyleHelper): Adding static constructor to StyleHelper class Adding static constructor to StyleHelper class Nov 17, 2022
@Kuldeep-MS Kuldeep-MS requested review from batzen and miloush November 17, 2022 09:33
internal static void RegisterAlternateExpressionStorage()
{
DependencyObject.RegisterForAlternativeExpressionStorage(
if(_getExpression == null)
Copy link
Member

@lindexi lindexi Nov 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After we register in static constructor, the _getExpression never be null when the other code call this method. And I think the RegisterAlternateExpressionStorage can be private and only called by static constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lindexi - Actually this method gets called from Style class's static ctor as well. That's when we'll have a case where _getExpression has already setup via StyleHelper's static ctor. Hence, this check prevents dual registration of the delegate.

Copy link
Contributor

@miloush miloush left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked both repros are fixed.

@dipeshmsft dipeshmsft merged commit c2615d9 into main Dec 28, 2022
@dipeshmsft dipeshmsft deleted the fix/styleHelper branch December 28, 2022 05:31
@ghost ghost locked as resolved and limited conversation to collaborators Jan 27, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

PR metadata: Label to tag PRs, to facilitate with triage

Projects

None yet

6 participants