Skip to content

Improve error message when provider does not support reverse engineering - #39209

Open
SkyDevLab wants to merge 3 commits into
dotnet:mainfrom
SkyDevLab:fix/14629-reveng-error-message
Open

SkyDevLab wants to merge 3 commits into
dotnet:mainfrom
SkyDevLab:fix/14629-reveng-error-message

Conversation

@SkyDevLab

Copy link
Copy Markdown
Contributor

Fixes #14629

Description

When reverse engineering / scaffolding (Scaffold-DbContext / dotnet ef dbcontext scaffold) with an unsupported database provider (such as Microsoft.EntityFrameworkCore.Cosmos, Microsoft.EntityFrameworkCore.InMemory, or any provider that does not implement reverse engineering design-time services), the user previously received a cryptic, unhelpful System.InvalidOperationException:

System.InvalidOperationException: Unable to find expected assembly attribute named DesignTimeProviderServicesAttribute in provider assembly Microsoft.EntityFrameworkCore.Cosmos. This attribute is required to identify the class which acts as the design-time service provider factory.
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.ConfigureProviderServices(String provider, IServiceCollection services, Boolean throwOnError)
   at Microsoft.EntityFrameworkCore.Design.Internal.DesignTimeServicesBuilder.Build(String provider)
   at Microsoft.EntityFrameworkCore.Design.Internal.DatabaseOperations.ScaffoldContext(...)

Directly analogous to #1652 where MigrationsOperations.EnsureServices checks if IMigrator is registered and throws OperationException(DesignStrings.NonRelationalProvider(providerName)):

  1. In DesignTimeServicesBuilder.ConfigureProviderServices, if DesignTimeProviderServicesAttribute is missing on the provider assembly, log verbose information and return rather than throwing an internal InvalidOperationException. Missing runtime provider assemblies still throw OperationException(DesignStrings.CannotFindRuntimeProviderAssembly).
  2. In DatabaseOperations.ScaffoldContext, call EnsureServices on the scoped service provider to ensure IDatabaseModelFactory has been registered. If not registered, throw OperationException(DesignStrings.CannotScaffoldProvider(provider)):
    The provider '{provider}' does not support reverse engineering.
  3. Added unit tests in DatabaseOperationsTest verifying that reverse engineering with an unsupported provider throws OperationException with the improved error message, and nonexistent provider assemblies continue to report missing provider assemblies.

@SkyDevLab
SkyDevLab requested a review from a team as a code owner October 9, 2026 17:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Add coverage for a loadable provider assembly without DesignTimeProviderServicesAttribute.

1 open finding
What changed in this PR

Improves reverse-engineering errors for providers that do not support scaffolding.

Changes:

  • Adds a clear unsupported-provider error.
  • Handles missing design-time provider services gracefully.
  • Adds tests for unsupported and missing providers.
File Reviewed change
test/​EFCore.Design.Tests/​Design/​Internal/​DatabaseOperationsTest.cs Tests provider error scenarios.
src/​EFCore.Design/​Properties/​DesignStrings.resx Adds the new error message.
src/​EFCore.Design/​Properties/​DesignStrings.Designer.cs Exposes the localized message.
src/​EFCore.Design/​Design/​Internal/​DesignTimeServicesBuilder.cs Handles missing design-time attributes.
src/​EFCore.Design/​Design/​Internal/​DatabaseOperations.cs Validates scaffolding service registration.
Files not reviewed (1)
  • src/EFCore.Design/Properties/DesignStrings.Designer.cs: Generated file

🧠 Review effort: Lite

Comment on lines +175 to +178
_reporter.WriteVerbose(
DesignStrings.CannotFindDesignTimeProviderAssemblyAttribute(provider));

throw new InvalidOperationException(message);
return;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added unit test coverage for a loadable provider assembly without DesignTimeProviderServicesAttribute (using Microsoft.EntityFrameworkCore) in commit 4d12e51.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RevEng: Improve error message when not supported

2 participants