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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 AmbiguosMatchFound Exception #1350

Closed
2 tasks
pentarex opened this issue Jun 10, 2022 · 1 comment
Closed
2 tasks

馃悰 AmbiguosMatchFound Exception #1350

pentarex opened this issue Jun 10, 2022 · 1 comment
Labels

Comments

@pentarex
Copy link

Describe the Bug

I am using AutoFixture to generate content for my protobuf responses.
Added ReadonlyCollectionPropertiesBehavior in order to generate RepeatedField data

Scenario

RepeatedField class has overloaded Add method which throws exception in AutoFixture.Kernel.InstanceMethodQuery
when executing the code:

public IEnumerable<IMethod> SelectMethods(Type type = default)
{
    var method = this.Owner.GetType().GetTypeInfo().GetMethod(this.MethodName);

    return method == null
        ? new IMethod[0]
        : new IMethod[] { new InstanceMethod(method, this.Owner) };
}

Expected Behavior

No Exception should be thrown.

Tasks

  • Updated all AutoFixture and related libraries
  • Confirmed in support forums if behavior is expected

More Information

I have already added a comment in the PR #1177
The fix that I am currently using is:

public IEnumerable<IMethod> SelectMethods()
{
    if(Owner == null) return Array.Empty<IMethod>();
    var methods = this.Owner.GetType().GetMethods();
    foreach (var methodInfo in methods)
    {
        if (methodInfo.Name == MethodName && methodInfo.GetParameters().Length == 1)
        {
            return new IMethod[]
            {
                new InstanceMethod(methodInfo, this.Owner)
            };
        }
    }
    
    return Array.Empty<IMethod>();
}

Would like to use it, but sadly SpecimentFactory.CreateMany requires a type and the method which does not is internal, so... have to wait :)

Screenshots

Thanks!

@pentarex pentarex added the bug label Jun 10, 2022
@pentarex
Copy link
Author

pentarex commented Jun 10, 2022

Duplicate of #1339

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant