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

ContextFactory - 'Multiple constructors accepting all given argument types have been found #991

Closed
werwin81 opened this issue May 20, 2021 · 6 comments

Comments

@werwin81
Copy link

werwin81 commented May 20, 2021

I have a Blazor project and I'm using a context class generated with the "Reverse Engeneer" option.

In use the following DbContextFactory Service in the startup class.

....
services.AddDbContextFactory(options => options
.UseSqlServer(
Configuration.GetConnectionString("MyDbConnection"),
o => o.EnableRetryOnFailure())
.EnableSensitiveDataLogging(true)
.EnableDetailedErrors(true));

services.AddScoped(p =>
p.GetRequiredService<IDbContextFactory>().CreateDbContext()
);
...

If I start the programm, the instruction
services.AddScoped(p =>
p.GetRequiredService<IDbContextFactory>().CreateDbContext()
);
produces the following error:

System.InvalidOperationException: 'Multiple constructors accepting all given argument types have been found in type 'MyContext'. There should only be one applicable constructor.'

If I remove the empty default constructor from the generated class, everything works.
Is it possible to prevent the creation of the default constructor?

Further technical details

EF Core Power Tools version: 2.5.659
Database engine: SQL Server

Visual Studio version: 16.9.6

@ErikEJ
Copy link
Owner

ErikEJ commented May 20, 2021

Which EF Core version?

@werwin81
Copy link
Author

EF Core 5.0.6

@ErikEJ
Copy link
Owner

ErikEJ commented May 20, 2021

Looks like it is an EF Core bug: dotnet/efcore#24124

@werwin81
Copy link
Author

Ok. Thank you for your response. I will look for another solution.

@ErikEJ
Copy link
Owner

ErikEJ commented May 20, 2021

Manually remove the constructor??

@ErikEJ
Copy link
Owner

ErikEJ commented Jul 11, 2021

Fixed in latest daily buidl: b85c77d

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

No branches or pull requests

2 participants