Fix config source gen binding with SslClientAuthenticationOptions#107579
Conversation
...ries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.Configuration.Binder/gen/Emitter/CoreBindingHelpers.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
| if (!_typeIndex.HasBindableMembers(complexType) && | ||
| !_typeIndex.GetEffectiveTypeSpec(complexType).IsValueType && | ||
| complexType is not CollectionSpec && | ||
| ((ObjectSpec)complexType).InstantiationStrategy == ObjectInstantiationStrategy.ParameterizedConstructor) |
There was a problem hiding this comment.
Can you explain all these conditions? I only understand the first, why the others?
There was a problem hiding this comment.
complexType is not CollectionSpec we have special handling to the collections so we should not change how we do it especially it should work in most cases. look at
((ObjectSpec)complexType).InstantiationStrategy == ObjectInstantiationStrategy.ParameterizedConstructor) is needed because if it is different ObjectInstantiationStrategy value means we can still create and handle the object. look at
There was a problem hiding this comment.
_typeIndex.GetEffectiveTypeSpec(complexType).IsValueType can be handled too,
There was a problem hiding this comment.
I was trying to scope the change to exact failure cases to reduce any risk of breaking anything.
There was a problem hiding this comment.
I see - I was surprised we'd even get this far with a type that has no bindable members and we're trying to construct with a parameterized constructor. I would have expected us to discover that in parsing and use a different spec type (not supported or something) - why do we miss this in parsing?
There was a problem hiding this comment.
That is because we want use _typeIndex which is created and filled in the emitter. If we want to do the detection earlier, we'll need to do more involving refactoring which will make the change risky for 9.0. Note, the parser fills some data structures which expect to see the type specs supported by _typeIndex later during the emission. so refactoring will not be simple IMO.
There was a problem hiding this comment.
I see - given that it seems like the parser isn't even capable of completely deciding which types will be handled. It can only decide which may be handled and we filter further during emit. That feels like something we'd need to fix to address other issues.
|
/backport to release/9.0 |
|
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10818391044 |
…tnet#107579) * Fix config source gen binding with SslClientAuthenticationOptions * Apply suggestions from code review Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
…tnet#107579) * Fix config source gen binding with SslClientAuthenticationOptions * Apply suggestions from code review Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com> --------- Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Fixes #107003