dotnet/efcore · critical · OperationException

Unable to find provider assembly '{assemblyName}'. Ensure th

Error message

Unable to find provider assembly '{assemblyName}'. Ensure the name is correct and it's referenced by the project.

What it means

Thrown by DesignTimeServicesBuilder when Assembly.Load(new AssemblyName(provider)) throws -- the configured database provider assembly (e.g. Microsoft.EntityFrameworkCore.SqlServer) could not be located/loaded at design time. EF needs the provider DLL to read its [DesignTimeProviderServices] attribute and wire up scaffolding/migration services. The inner exception carries the loader failure (FileNotFound, version mismatch, etc.).

Source

Thrown at src/EFCore.Design/Design/Internal/DesignTimeServicesBuilder.cs:169

        _reporter.WriteVerbose(DesignStrings.FindingProviderServices(provider));

        Assembly providerAssembly;
        try
        {
            providerAssembly = Assembly.Load(new AssemblyName(provider));
        }
        catch (Exception ex)
        {
            var message = DesignStrings.CannotFindRuntimeProviderAssembly(provider);

            if (!throwOnError)
            {
                _reporter.WriteVerbose(message);

                return;
            }

            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);
        }

View on GitHub (pinned to dbf9771522)

Solutions

  1. Install the matching EF Core provider package into the STARTUP project: dotnet add package Microsoft.EntityFrameworkCore.SqlServer.
  2. Make sure the same major EF Core version is used across all projects.
  3. Run dotnet ef with --startup-project pointing at the project that has the provider reference.
  4. Rebuild after adding the package so the assembly is present on disk.

Example fix

// before: DbContext in Data project, no provider in Web project
dotnet ef migrations add Init -p ../Data
// after
// (in Web project dir)
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
dotnet ef migrations add Init -p ../Data -s .
Defensive patterns

Strategy: validation

Validate before calling

// At startup, verify the provider assembly is loadable.
try { _ = Assembly.Load(providerAssemblyName); }
catch (Exception ex) { throw new InvalidOperationException($"Provider assembly '{providerAssemblyName}' not loadable. Install the package.", ex); }

Try / catch

try { /* operation requiring provider */ }
catch (OperationException ex) when (ex.Message.Contains("Unable to find provider assembly"))
{ /* install Microsoft.EntityFrameworkCore.<Provider> in the startup project, rebuild, retry */ }

Prevention

When it happens

Trigger: DbContext.OnConfiguring calls options.UseSqlServer (or UseNpgsql, etc.) but the provider NuGet package is not installed in the startup/entry project being used at design time. Build(context) walks providers, calls ConfigureProviderServices -> Assembly.Load(provider) which throws.

Common situations: Provider package installed only in the data project, not the startup project EF executes against; package was uninstall-cleaned; a version downgrade left a binding redirect gap; running dotnet ef from the wrong directory.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/9f80472a42bf51c7. Report an issue: GitHub.