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

Passing null for a Nullable<T> parameter fails with AmbiguousMatchException #603

Open
1 task done
khellang opened this issue May 2, 2024 · 0 comments · May be fixed by #604
Open
1 task done

Passing null for a Nullable<T> parameter fails with AmbiguousMatchException #603

khellang opened this issue May 2, 2024 · 0 comments · May be fixed by #604
Labels
team/server-at-scale Describes the Octopus Deploy team called Server At Scale

Comments

@khellang
Copy link

khellang commented May 2, 2024

Team

  • I've assigned a team label to this issue

What happened?

When passing null to an asynchronous service method accepting a Nullable<T> parameter, Halibut will not consider it a match and fails with the following exception:

Halibut.Exceptions.AmbiguousMethodMatchHalibutClientException : Could not decide which candidate to call out of the following methods:
 - System.Threading.Tasks.Task`1[System.Int32] IncrementAsync(System.Threading.CancellationToken)
 - System.Threading.Tasks.Task`1[System.Int32] IncrementAsync(System.Nullable`1[System.Int32], System.Threading.CancellationToken)
The request arguments were:
<null>

Reproduction

Define an async service method like this:

    public interface ICountingService
    {
        public int Increment(int? number);
    }

    public interface IAsyncCountingService
    {
        public Task<int> IncrementAsync(int? number, CancellationToken cancellationToken);
    }

And invoke it like this:

[Test]
public async Task AsyncInvokeWithNullableParamsOnAsyncService()
{
    var serviceFactory = new ServiceFactoryBuilder()
        .WithConventionVerificationDisabled()
        .WithService<ICountingService, IAsyncCountingService>(() => new AsyncCountingService())
        .Build();

    var sut = new ServiceInvoker(serviceFactory);
    var request = new RequestMessage()
    {
        ServiceName = nameof(ICountingService),
        MethodName = nameof(ICountingService.Increment),
        Params = new object[] { null! },
    };

    var response = await sut.InvokeAsync(request);
    response.Result.Should().Be(1);
}

Error and Stacktrace

Halibut.Exceptions.AmbiguousMethodMatchHalibutClientException : Could not decide which candidate to call out of the following methods:
 - System.Threading.Tasks.Task`1[System.Int32] IncrementAsync(System.Threading.CancellationToken)
 - System.Threading.Tasks.Task`1[System.Int32] IncrementAsync(System.Nullable`1[System.Int32], System.Threading.CancellationToken)
The request arguments were:
<null>

More Information

I have written a test and patched the bug, will submit a PR ASAP.

Workaround

No response

@rhysparry rhysparry added the team/server-at-scale Describes the Octopus Deploy team called Server At Scale label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team/server-at-scale Describes the Octopus Deploy team called Server At Scale
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants