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

  1. On the custom provider assembly, add [assembly: DesignTimeProviderServices(typeof(MyDesignTimeServices))] pointing at an IDesignTimeServices implementation.
  2. Ensure the attribute's TypeName resolves to a concrete type implementing IDesignTimeServices in that assembly.
  3. If using a third-party provider, upgrade it to a version that ships the attribute.
  4. 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

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


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)