question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GenAPI can generate ambiguous call to base constructor

See original GitHub issue

When GenAPI defines arguments to a base constructor, it uses default! but this can lead to an ambiguous call when the base type has constructor overloads with the same number of parameters but different types.

An example of this is the generated code for NuGet.Protocol.6.5.0:

public partial class SourcePackageDependencyInfo : Packaging.Core.PackageDependencyInfo
{
    public SourcePackageDependencyInfo(Packaging.Core.PackageIdentity identity, System.Collections.Generic.IEnumerable<Packaging.Core.PackageDependency> dependencies, bool listed, SourceRepository source, System.Uri downloadUri, string packageHash) : base(default!, default!) { }

This leads to the following compiler error:

error CS0121: The call is ambiguous between the following methods or properties: 'PackageDependencyInfo.PackageDependencyInfo(PackageIdentity, IEnumerable<PackageDependency>)' and 'PackageDependencyInfo.PackageDependencyInfo(string, NuGetVersion)

This can be solved by explicitly casting default to the desired type:

: base((Packaging.Core.PackageIdentity)default!, (System.Collections.Generic.IEnumerable<Packaging.Core.PackageDependency>)default!) { }

cc @andriipatsula @ViktorHofer

Issue Analytics

  • State:closed
  • Created 5 months ago
  • Comments:9 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
ericstjcommented, Apr 25, 2023

Fix is in https://github.com/dotnet/roslyn/pull/67893. Once we can get a new build of roslyn with this fix in SDK we can resolve this (and re-enable the test).

Read more comments on GitHub >

github_iconTop Results From Across the Web

GenAPI can generate ambiguous call to base constructor
When GenAPI defines arguments to a base constructor, it uses default! but this can lead to an ambiguous call when the base type...
Read more >
Call to template base constructor is ambiguous
You can solve your problem by making the constructor call unambiguous: template<class T> struct Foo: public T, public Bar<T> { Foo(): ...
Read more >
Why does the error message “Call to constructor of ' ' is ...
ambiguous means the compiler found multiple “valid” choices and refused to make the choice for you. You need to add clarifying information (usually...
Read more >
Ambiguous call false positive error when using constructor ...
CPP-11804 Using-declaration to inherit ctors resolves object construction as ambiguous if derived and base class have ctors with same signature.
Read more >
Ambiguous call error during compilation when explicit ...
In this case compiler takes both f() functions but it should notice, that first is not available and it should generate code with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found