-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Fix PropertyGetter to handle value types correctly in SupplyParameterFromPersistentComponentStateValueProvider #62369
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
… tests Co-authored-by: javiercn <[email protected]>
…orks correctly Co-authored-by: javiercn <[email protected]>
Co-authored-by: javiercn <[email protected]>
@@ -11,5 +11,6 @@ internal static class JsonSerializerOptionsProvider | |||
{ | |||
PropertyNamingPolicy = JsonNamingPolicy.CamelCase, | |||
PropertyNameCaseInsensitive = true, | |||
IncludeFields = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is for ValueTuples
@@ -46,7 +48,7 @@ public PropertyGetter(Type targetType, PropertyInfo property) | |||
|
|||
public object? GetValue(object target) => _GetterDelegate(target); | |||
|
|||
private static TValue CallPropertyGetter<TTarget, TValue>( | |||
private static object? CallPropertyGetter<TTarget, TValue>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to box the value here as opposed to later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot don't do anything. This is just an explanatory comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 3522b26 - added explicit boxing using (object?)
cast to ensure value is boxed within the method rather than at the return boundary.
…xplicitly Co-authored-by: javiercn <[email protected]>
@@ -107,6 +107,6 @@ | |||
public class TestServiceProvider : IServiceProvider | |||
{ | |||
public object GetService(Type serviceType) | |||
=> throw new NotImplementedException(); | |||
=> null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests were failing.
I don't know how they got to pass on the Validation PR (and for that to get merged).
https://github.com/dotnet/aspnetcore/runs/44279307019
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was throwing when trying to retrieve the validation options, the fix is to just return null.
The
PropertyGetter
class was failing to create delegates for properties on components with value type properties, throwing "Cannot bind to the target method because its signature is not compatible with that of the delegate type" exceptions during prerendering.Problem
When using
[SupplyParameterFromPersistentComponentState]
with value type properties likeint?
, tuples, etc., the PropertyGetter constructor would fail during delegate creation:Root Cause
The
PropertyGetter
constructor was always usingtypeof(Func<,>)
for delegate creation, but the CLR requires different handling for value types vs reference types when creating delegates from instance methods. The sharedPropertyHelper
class already had the correct implementation pattern.Solution
Updated
PropertyGetter
to follow the same pattern as the sharedPropertyHelper
:ByRefFunc<TDeclaringType, TValue>
delegate type for by-reference property access on value typesCallPropertyGetterByReference
method to handle value type property accessobject?
for compatibilityint
,int?
, and tuple value type propertiesKey Changes
ByRefFunc<TDeclaringType, TValue>
delegate type for value typesCallPropertyGetterByReference
method for by-reference property accessobject?
instead ofTValue
for delegate compatibilitygetMethod.DeclaringType.IsValueType
and use appropriate delegate creation pathTesting
int
andint?
value types passThe PropertyGetter now correctly handles value type properties without throwing delegate creation exceptions.
Fixes #62368.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.