dotnet / dotnet/efcore

ApplyConfigurationsFromAssembly warns about no parameterless constructor for already added DB Configurations

Open
#35,396 6 comments 0 reactions 1 assignee Claimed by @AndriySvyryd View on GitHub
area-model-building customer-reported
Dominant language
C#
Stars
14.8k
Forks
3.4k
PR merge metrics
PR metrics pending

Description

I just upgraded to .NET 9 from .NET 8 and now get a new warning in my logs: "The type '{entityTypeConfig}' was found while scanning assemblies but could not instantiated because it does not have a parameterless constructor."

While I like the concept for error-catching, I get this for `UserOAuthAuthorizationDbConfiguration` even its configuration is manually added right before the call to `ApplyConfigurationsFromAssembly`. It requires an encryption utility, so it will never have a parameterless constructor. Consequently, the warning in the log is just noise. ;)

See my `OnModelCreating` method of my DbContext class:

```
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasPostgresExtension("uuid-ossp");

modelBuilder.ApplyConfiguration(new UserOAuthAuthorizationDbConfiguration(this.GetService()));

var asm = GetType().Assembly;
modelBuilder.ApplyConfigurationsFromAssembly(asm, type => modelBuilder.Model.FindEntityType(type) == null);
}
```

This seems related to #19691, #32577 and #24748

I believe the `ApplyConfigurationsFromAssembly` should skip any already loaded configurations.

### Include provider and version information

EF Core version: 9.0.0
Database provider: Npgsql.EntityFrameworkCore.PostgreSQL 9.0.2
Target framework: .NET 9
Operating system: Windows 11 Pro
IDE: Jetbrains Rider

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.