dotnet/efcore · error · InvalidOperationException
Unable to find expected assembly attribute…
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
InvalidOperationException thrown when the loaded provider assembly does not carry [DesignTimeProviderServices] attribute. That attribute names the IDesignTimeServices implementation that registers scaffolding/migration services; without it the design-time pipeline cannot find provider-specific services.
Solutions
- On the custom provider assembly, add [assembly: DesignTimeProviderServices(typeof(MyDesignTimeServices))] pointing at an IDesignTimeServices implementation.
- Ensure the attribute's TypeName resolves to a concrete type implementing IDesignTimeServices in that assembly.
- If using a third-party provider, upgrade it to a version that ships the attribute.
- Verify the runtime provider assembly name passed to the tools is the one that carries the attribute (not a split runtime/design package mismatch).
Example fix
// before - custom provider assembly has no design-time attribute
[assembly: AssemblyVersion("1.0.0.0")]
// after
using Microsoft.EntityFrameworkCore.Design;
[assembly: DesignTimeProviderServices(typeof(MyProvider.Design.MyDesignTimeServices))]
public sealed class MyDesignTimeServices : IDesignTimeServices
{
public void ConfigureDesignTimeServices(IServiceCollection services)
=> services.AddSingleton<IDatabaseModelFactory, MyDatabaseModelFactory>();
} Defensive patterns
Strategy: validation
Validate before calling
var attr = providerAssembly.GetCustomAttribute<DesignTimeProviderServicesAttribute>();
if (attr is null)
throw new InvalidOperationException($"{providerAssembly.GetName().Name} lacks [DesignTimeProviderServices]; add the attribute to its IDesignTimeServices type."); Type guard
static bool ProviderHasDesignTimeAttribute(Assembly a)
=> a.GetCustomAttribute<DesignTimeProviderServicesAttribute>() is not null;
Try / catch
try { /* design-time op */ }
catch (InvalidOperationException ex) when (ex.Message.Contains("DesignTimeProviderServices"))
{ /* decorate the provider assembly with the attribute pointing at its IDesignTimeServices */ } Prevention
- Decorate every custom provider assembly with [assembly: DesignTimeProviderServices(typeof(X))].
- Ensure the TypeName resolves to a concrete IDesignTimeServices in the same assembly.
- Cover provider design-time setup with a unit test that asserts the attribute exists.
When it happens
Trigger: A custom or third-party provider assembly is loaded successfully but is missing the DesignTimeProviderServicesAttribute. The runtime provider works but the design-time layer (migrations, scaffold) cannot locate its services factory.
Common situations: Building a custom EF provider and forgetting to decorate the assembly with [DesignTimeProviderServices(typeof(...))]; or referencing a provider shim/proxy assembly that forwards runtime calls but lacks the design-time hook.
Related errors
- Metadata model returned should not be 'null'. Provider
- Unable to find provider assembly
- A type-qualified method call requires an instance…
- Cannot scaffold C# literals of type
- Compilation failed with errors:
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/a8b35de2bfdda075.
Report an issue: GitHub.
Appendix: 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 3a2006ef56)