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 · 2 comments
Labels
area-model-building closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported

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

@AndriySvyryd AndriySvyryd removed their assignment Jan 8, 2025
@AndriySvyryd AndriySvyryd added the closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. label Jan 8, 2025
@AndriySvyryd
Copy link
Member

This is out-of-scope for EF Core. I encourage you to create a copy ApplyConfigurationsFromAssembly and customize it to your needs.

@dstj
Copy link
Author

dstj commented Jan 8, 2025

@AndriySvyryd
I'll look at that option, thanks. But I respectfully disagree that avoiding false-positive warnings is out-of-scope. I don't think my use case is so far fetched. Is it???

Can you point out how I would access the list of already registered IEntityTypeConfiguration<> from a copy of ApplyConfigurationsFromAssembly?

Plus, sidenote, trying to copy ApplyConfigurationsFromAssembly forces me to cascade copy SharedTypeExtensions.GetConstructibleTypes and SharedTypeExtensions.GetLoadableDefinedTypes because SharedTypeExtensions is internal.

It, more and more, feels like there should be a simpler way to avoid this warning...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-out-of-scope This is not something that will be fixed/implemented and the issue is closed. customer-reported
Projects
None yet
Development

No branches or pull requests

3 participants