Creating migration w/ startup-project with multiple overloads of CreateHostBuilder gives 'Ambiguous match found.' error
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
I'm working on a solution with several projects, one of them being the application host and another being the database project, containing databasecontext and migrations.
When trying to create a new migration using, with the database project root being the current working directory.
```
dotnet-ef migrations add Init -s ..\..\ApplicationHost\MyApplicationHost
```
It gives the following output:
```csharp
Build started...
Build succeeded.
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.DefaultBinder.FindMostDerivedNewSlotMeth(MethodBase[] match, Int32 cMatches)
at System.RuntimeType.GetMethodImplCommon(String name, Int32 genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name, BindingFlags bindingAttr)
at System.Reflection.TypeInfo.GetDeclaredMethod(String name)
at Microsoft.Extensions.Hosting.HostFactoryResolver.ResolveFactory[T](Assembly assembly, String name)
at Microsoft.Extensions.Hosting.HostFactoryResolver.ResolveHostBuilderFactory[THostBuilder](Assembly assembly)
at Microsoft.Extensions.Hosting.HostFactoryResolver.ResolveServiceProviderFactory(Assembly assembly)
at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.CreateFromHosting(String[] args)
at Microsoft.EntityFrameworkCore.Design.Internal.AppServiceProviderFactory.Create(String[] args)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextTypes()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.FindContextType(String name)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.AddMigration(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigration.<>c__DisplayClass0_0.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Ambiguous match found.
```
I quickly figured out the problem, but only because I had just experimented with only having a generic `CreateHostBuilder` which gave the semi-clear error `Late bound operations cannot be performed on types or methods for which ContainsGenericParameters is true`.
### Steps to reproduce
Have multiple overloads of
```csharp
public static IHostBuilder CreateHostBuilder(string[] args)
```
I.e., I also had
```csharp
public static IHostBuilder CreateHostBuilder(string[] args) where TStartup : class
```
So I just renamed the generic overload and that fixed the problem.
This bug report is about either supporting overloads of `CreateHostBuilder`, which I think could be possible, or just give a more clear error message. Perhaps include what it is, that is ambigous, f.x. the name of the function.
### Further technical details
EF Core version: 3.1.3
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL
Target framework: .NET Core 3.1
Operating system: Windows 10 Enterprise
IDE: Rider 2020.1.1
Contributor guide
Assessment
This issue has not been assessed yet.