Skip to content

Property indexers raises ' System.Reflection.AmbiguousMatchException: Ambiguous match found.' exception. #1129

Closed
@mujdatdinc

Description

@mujdatdinc

Property indexers raises ' System.Reflection.AmbiguousMatchException: Ambiguous match found.' exception.

Interface IndexerInterface
         ReadOnly Property SystemDefault() As Boolean
         Property Value() As Boolean
         Property Value(ByVal OverrideLevel As Integer) As Boolean
         Property Value(ByVal OverrideLevel As Integer, ByVal OverrideID As String) As Boolean
     End Interface
           Dim failClassMock = New Mock(Of IndexerInterface)()

            failClassMock.SetupAllProperties()

            Assert.False(failClassMock.Object.Value)

Using the class above, after SetupAllProperties are called Value raises the exception in line.
This line should call GetProperty(name,new Type[0]) with zero parameters. As there are 2 get_Value method.

Version: 4.15.2

Activity

stakx

stakx commented on Jan 14, 2021

@stakx
Contributor

Interesting find! Are you sure that's the correct line of code? After all, type.GetProperty is looking for properties, not for methods. I would expect that method to identify properties through their own metadata and not through their accessor methods...?

mujdatdinc

mujdatdinc commented on Jan 14, 2021

@mujdatdinc
Author

VB can create indexer properites. C# can do it as a method. I fixed it in my local and my tests are working.

added a commit that references this issue on Jan 15, 2021
mujdatdinc

mujdatdinc commented on Jan 15, 2021

@mujdatdinc
Author

I created the unit test and fix.
mujdatdinc:issue/1129
I am changing the initial post for details.

added this to the 4.16.1 milestone on Jan 16, 2021
stakx

stakx commented on Jan 16, 2021

@stakx
Contributor

@mujdatdinc, ah yes, that makes sense now! 👍

Would you like to submit a PR with your bug fix?

If so, it would be great if you could do the following (as explained in more detail in the contribution guidelines):

  • Add your repro to tests/Moq.Tests.VisualBasic/IssueReports.vb like you did in your commit. (Please pay attention to indentation: This project uses tabs, not spaces; so there should be no change to existing code.)

  • Put the actual bug fix in src/Moq/Interception/InterceptionAspects.cs. (Again, please don't change indentation of existing code. Also, you can use Type.EmptyTypes instead of new Type[0]; there's no need to allocate a new array when we can use an existing one.)

  • Add a new entry to CHANGELOG.md describing your bug fix.

(P.S.: Seeing that this is your first issue on GitHub, please don't hesitate to ask for guidance, if needed.)

mujdatdinc

mujdatdinc commented on Jan 17, 2021

@mujdatdinc
Author

Thanks. I send the PR. Hope its ok.
Actualy I have one more bug that breaks some of our unit tests. I fixed with work around but work around its annoying. I will open when i have time.

6 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

    Participants

    @stakx@mujdatdinc

    Issue actions

      Property indexers raises ' System.Reflection.AmbiguousMatchException: Ambiguous match found.' exception. · Issue #1129 · devlooped/moq