Skip to content

Fix Binding with IDictionary<,> implementer types - #77582

Merged
tarekgh merged 3 commits into
dotnet:mainfrom
tarekgh:FixConfigurationBindingWithDictionary
Oct 30, 2022
Merged

Fix Binding with IDictionary<,> implementer types#77582
tarekgh merged 3 commits into
dotnet:mainfrom
tarekgh:FixConfigurationBindingWithDictionary

Conversation

@tarekgh

Copy link
Copy Markdown
Member

Fixes#77246

In .NET 7.0 we have done some refactoring work in the configuration binding code #68133. The refactored code work fine when binding to IDictionary<,> interface or Dictionary<,> based class but it broke the case when using a type which implementing IDictionary<,> interface. The new code was always creating Dictionary<,> type and then getting the setter of the Item property from that type. But the object used in the binding is not of type Dictionary<,> at all and the property setter fails because it is used with wrong type.

@ghost

Copy link
Copy Markdown

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #77246

In .NET 7.0 we have done some refactoring work in the configuration binding code #68133. The refactored code work fine when binding to IDictionary<,> interface or Dictionary<,> based class but it broke the case when using a type which implementing IDictionary<,> interface. The new code was always creating Dictionary<,> type and then getting the setter of the Item property from that type. But the object used in the binding is not of type Dictionary<,> at all and the property setter fails because it is used with wrong type.

Author:tarekgh
Assignees:-
Labels:

area-Extensions-Configuration

Milestone:-

@tarekgh

Copy link
Copy Markdown
MemberAuthor

CC @SteveDunn

@SteveDunnSteveDunn left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - sorry I didn't address the issue myself but I'm a bit busy in my day job right now.

@tarekgh
tarekgh merged commit e6700ea into dotnet:mainOct 30, 2022
@tarekgh
tarekgh deleted the FixConfigurationBindingWithDictionary branch October 30, 2022 17:36
@tarekgh

Copy link
Copy Markdown
MemberAuthor

/backport to release/7.0

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/3430573766

@ghostghost locked as resolved and limited conversation to collaborators Dec 9, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConfigurationBinder fails to bind class that implements IDictionary

4 participants

@tarekgh@SteveDunn@maryamariyan@eerhardt