Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mujdatdinc opened this issue Jan 14, 2021 · 5 comments · Fixed by #1131
Assignees
Labels
Milestone

Comments

@mujdatdinc
Copy link

mujdatdinc commented Jan 14, 2021

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

@stakx
Copy link
Contributor

stakx commented Jan 14, 2021

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
Copy link
Author

mujdatdinc commented Jan 14, 2021

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

mujdatdinc pushed a commit to mujdatdinc/moq4 that referenced this issue Jan 15, 2021
@mujdatdinc
Copy link
Author

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

@stakx stakx added the bug label Jan 16, 2021
@stakx stakx added this to the 4.16.1 milestone Jan 16, 2021
@stakx
Copy link
Contributor

stakx commented Jan 16, 2021

@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 pushed a commit to mujdatdinc/moq4 that referenced this issue Jan 16, 2021
mujdatdinc pushed a commit to mujdatdinc/moq4 that referenced this issue Jan 16, 2021
@mujdatdinc
Copy link
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.

mujdatdinc pushed a commit to mujdatdinc/moq4 that referenced this issue Jan 17, 2021
mujdatdinc pushed a commit to mujdatdinc/moq4 that referenced this issue Jan 17, 2021
stakx pushed a commit that referenced this issue Jan 17, 2021
mburumaxwell pushed a commit to faluapp/falu-dotnet that referenced this issue Jun 12, 2021
Bumps [Moq](https://github.com/moq/moq4) from 4.16.0 to 4.16.1.

#Changelog

*Sourced from [Moq's changelog](https://github.com/moq/moq4/blob/main/CHANGELOG.md).*

> ## 4.16.1 (2021-02-23)
>
> #### Added
>
> * `CallBase` can now be used with interface methods that have a default interface implementation. It will call [the most specific override](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-8.0/default-interface-methods#the-most-specific-override-rule). (@stakx, [#1130](devlooped/moq#1130))
>
> #### Changed
>
> * Improved error message formatting of `It.Is` lambda expressions that capture local variables. (@bfriesen, [#1140](devlooped/moq#1140))
>
> #### Fixed
>
> * `AmbiguousMatchException` raised when interface has property indexer besides property in VB. (@mujdatdinc, [#1129](devlooped/moq#1129))
> * Interface default methods are ignored (@hahn-kev, [#972](devlooped/moq#972))
> * Callback validation too strict when setting up a task's `.Result` property (@stakx, [#1132](devlooped/moq#1132))
> * `setup.Returns(InvocationFunc)` wraps thrown exceptions in `TargetInvocationException` (@stakx, [#1141](devlooped/moq#1141))

#Commits

- [`fc484fb`](devlooped/moq@fc484fb) Update version to 4.16.1
- [`0ddfdb8`](devlooped/moq@0ddfdb8) `Returns(InvocationFunc)` shouldn't throw `TargetInvocationException`
- [`f36d3e8`](devlooped/moq@f36d3e8) Merge pull request [#1140](devlooped/moq#1140) from bfriesen/lambda_closure_support
- [`e96804f`](devlooped/moq@e96804f) Update the changelog
- [`5ae449c`](devlooped/moq@5ae449c) Exclude name of the closure class
- [`8a2d2ed`](devlooped/moq@8a2d2ed) Add test for closure access
- [`cf5af87`](devlooped/moq@cf5af87) Format lambda expression variables
- [`5b10a8c`](devlooped/moq@5b10a8c) Add test for lamba matcher variables
- [`653db31`](devlooped/moq@653db31) Some minor renames for consistency
- [`fc73131`](devlooped/moq@fc73131) Add missing copyright notices
- Additional commits viewable in [compare view](devlooped/moq@v4.16.0...v4.16.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants