Binder throw ambiguous match exception for object with read only indexer property that has two implementations in base class
- Dominant language
- C#
- Stars
- 9.7k
- Forks
- 538
- PR merge metrics
- No merged PRs in 30d
Description
### Version Information
| Software | Version(s) |
| ------------------------| ---------- |
| Bogus NuGet Package | 34.0.2 |
| .NET Core? | 7.0.11 |
| .NET Full Framework? | |
| Windows OS? | 11 Pro 22621.2283 |
| Linux OS? | |
| Visual Studio? | 17.8.0 Preview 2.0 |
### What locale are you using with Bogus?
en
### What is the expected behavior?
Should not throw exception when enumerating properties.
### What is the actual behavior?
System.Reflection.AmbiguousMatchException is thrown
### Please provide a stack trace.
at System.RuntimeType.GetPropertyImpl(String name, BindingFlags bindingAttr, Binder binder, Type returnType, Type[] types, ParameterModifier[] modifiers)
### Any possible solutions?
Yes it is possible to ignore the indexer properties where the check for parent class properties is performed.
Have created a [branch in my fork with a unit test and a possible solution](https://github.com/bchavez/Bogus/compare/master...AlesDo:Bogus:FluenSyntaxIndexerBug).
### How do you reproduce the issue?
By using fluent syntax with an object that has two read only indexers that are defined in a base class.
Have created a [branch in my fork with a unit test and a possible solution](https://github.com/bchavez/Bogus/compare/master...AlesDo:Bogus:FluenSyntaxIndexerBug).
### Do you have a unit test that can demonstrate the bug?
Yes.
Have created a [branch in my fork with a unit test and a possible solution](https://github.com/bchavez/Bogus/compare/master...AlesDo:Bogus:FluenSyntaxIndexerBug).
### Can you identify the location in Bogus' source code where the problem exists?
Yes.
Binder.cs line 114. Because both indexers have same default name Item resolving PropertyInfo by name fails.
### If the bug is confirmed, would you be willing to submit a PR?
Yes.
Contributor guide
Research direction
Start with Binder.cs at line 114 and review the parent-class property check. Reproduce the fluent-syntax case using the unit test from the linked fork branch: an object with two read-only indexers inherited from a base class. Done means property enumeration no longer throws AmbiguousMatchException and the regression test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100