dotnet/efcore · critical · InvalidOperationException
Unable to find expected assembly attribute [DesignTimeProvid
Error message
Unable to find expected assembly attribute [DesignTimeProviderServices] in provider assembly '{runtimeProviderAssemblyName}'. This attribute is required to identify the class which acts as the design-time service provider factory for the provider. What it means
The provider assembly loaded fine, but it has no [DesignTimeProviderServices] attribute, which EF uses to locate the class that registers the provider's design-time services (scaffolding, SQL generators, etc.). This almost always means the assembly is not a real EF Core provider, or is an incompatible/old one. It is thrown as InvalidOperationException (not OperationException) because it indicates a corrupt or wrong provider rather than user input.
Source
Thrown at src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs:185
}
throw new OperationException(message, ex);
}
var providerServicesAttribute = providerAssembly.GetCustomAttribute<DesignTimeProviderServicesAttribute>();
if (providerServicesAttribute == null)
{
var message = DesignStrings.CannotFindDesignTimeProviderAssemblyAttribute(
provider);
if (!throwOnError)
{
_reporter.WriteVerbose(message);
return;
}
throw new InvalidOperationException(message);
}
var designTimeServicesType = providerAssembly.GetType(
providerServicesAttribute.TypeName,
throwOnError: true,
ignoreCase: false)!;
_reporter.WriteVerbose(DesignStrings.UsingProviderServices(provider));
ConfigureDesignTimeServices(designTimeServicesType, services);
}
private static void ConfigureDesignTimeServices(
Type designTimeServicesType,
IServiceCollection services)
{
Check.DebugAssert(designTimeServicesType != null, "designTimeServicesType is null.");
View on GitHub (pinned to dbf9771522)
Solutions
- Verify the package is an EF Core provider: install the official Microsoft.EntityFrameworkCore.<Provider> package.
- If using a custom/community provider, ensure its assembly is decorated with [DesignTimeProviderServices(typeof(...))] and that the design-time services type exists.
- Upgrade the provider to a version that matches your EF Core runtime version.
- Remove any stray Use* call that references a non-provider assembly.
Example fix
// before: wrong package options.UseSqlServer(connection); // but only System.Data.SqlClient referenced // after // dotnet add package Microsoft.EntityFrameworkCore.SqlServer options.UseSqlServer(connection);
Defensive patterns
Strategy: validation
Validate before calling
var attr = Assembly.Load(providerAssemblyName)
.GetCustomAttribute<DesignTimeProviderServicesAttribute>();
if (attr is null) throw new InvalidOperationException($"'{providerAssemblyName}' is not an EF Core provider (missing DesignTimeProviderServices attribute)."); Prevention
- Use only official Microsoft.EntityFrameworkCore.<Provider> packages.
- For custom providers, always decorate the assembly with [DesignTimeProviderServices].
- Run a smoke-test that loads the provider and checks for the attribute.
When it happens
Trigger: ConfigureProviderServices succeeds in loading the assembly (line 156) but providerAssembly.GetCustomAttribute<DesignTimeProviderServicesAttribute>() returns null at line 172. Happens when UseSqlServer points at a plain library, a hand-rolled provider lacking the attribute, or a provider built against a different EF Core design API.
Common situations: Pointing Use*[provider] at an ADO.NET driver instead of the EF provider (e.g. System.Data.SqlClient vs Microsoft.EntityFrameworkCore.SqlServer); using a community provider that dropped design-time support; a custom provider whose DesignTimeProviderServicesAttribute was removed in a refactor.
Related errors
- Unable to find provider assembly '{assemblyName}'. Ensure th
- The provider '{provider}' is not a Relational provider and t
- Unhandled annotatable type '{annotatableType}'.
- Cosmos-specific methods can only be used when the context is
- The container with the name '{containerName}' does not exist
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/a8b35de2bfdda075.
Report an issue: GitHub.