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

ApplyConfigurationsFromAssembly warns about no parameterless constructor for already added DB Configurations #35396

Open
dstj opened this issue Jan 1, 2025 · 0 comments

Comments

@dstj
Copy link

dstj commented Jan 1, 2025

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<IEncryptionUtil>()));
               

		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

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

No branches or pull requests

1 participant