[release/7.0] Fix configuration binding with types implementing IDictionary<,> #79019
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.
Fixes #78938
Backport of #78946 to release/7.0
/cc @tarekgh
Customer Impact
This issue is reported by the app-compat runs when running mixcore/mix.core app. The app will throw
System.Reflection.AmbiguousMatchException
during the configuration binding. This is a regression from the fix #78118 we had in7.0.1
servicing. This problem occur only if the app is using a type implementingIDictionary<,>
and include members with the same names asIDictionary<,>
members. Like class indexerthis[]
orTryGetValue
method. When using such class with the configuration, we use the reflection to bind to such class using the type indexer andTryGetValue
method. If there is multiple members with the same name, the reflection will throwAmbiguousMatchException
.Testing
I have tested the exact code used to repro the issue with the app-compat run with referencing the packages
Quartz.AspNetCore v3.3.3
andQuartz.Extensions.DependencyInjection v3.3.3
which causing the problem. I have run all our tests against the fix which is covering all cases we fixed before to ensure no other regressions. Also, I have added extra test to catch the issue we are fixing here.Risk
Medium, touching configuration code comes with some risk but I tried my best testing the change to ensure will not cause any other regressions.