dotnet/efcore · error · InvalidOperationException
Metadata model returned should not be 'null'. Provider
Error message
Metadata model returned should not be 'null'. Provider: {providerTypeName}. What it means
Thrown after the database provider's IScaffoldingModelFactory.Create() returns null when converting the reverse-engineered DatabaseModel into an EF IModel. EF Core requires a non-null model from the provider; a null return signals an internal provider defect, not a user modeling problem. The message names the offending factory type to localize the bug.
Solutions
- Update the database provider package (e.g. Microsoft.EntityFrameworkCore.SqlServer, Pomelo, Npgsql) to the version matching your EFCore.Design/EFCore version.
- If using a custom or preview provider, inspect its IScaffoldingModelFactory implementation for a code path that returns null.
- Open an issue with the provider project, including the factory type name from the message and the database schema that triggered it.
- As a workaround, scaffold against SQL Server/SQLite/localdb to validate the rest of the pipeline, then swap providers.
Example fix
// before: mismatched versions // EFCore.Design 8.0.x + provider 7.0.x // after: align patch versions // dotnet add package Microsoft.EntityFrameworkCore.SqlServer --version 8.0.x // dotnet add package Microsoft.EntityFrameworkCore.Design --version 8.0.x
Defensive patterns
Strategy: validation
Validate before calling
// Before scaffolding, confirm provider + design versions match
var designVer = typeof(DesignStrings).Assembly.GetName().Version;
var providerVer = providerAssembly.GetName().Version;
if (designVer.Major != providerVer.Major)
{
throw new InvalidOperationException($"Provider {providerVer} mismatches EFCore.Design {designVer}");
} Prevention
- Keep EFCore.Design and every provider package on the same major+minor release.
- Run scaffold against a known-good provider first to validate the pipeline.
- Pin provider versions in Directory.Packages.props to avoid transitive drift.
When it happens
Trigger: Calling ScaffoldModel/Scaffold (or `dotnet ef dbcontext scaffold`) against a provider whose IScaffoldingModelFactory implementation returns null from Create(databaseModel, modelOptions). Reached once the database schema has been read successfully and the model-building step begins.
Common situations: A third-party or custom EF Core provider whose scaffolding adapter is incomplete or mismatched to the installed EFCore.Design version. Rarely, a provider version regression after upgrading EFCore.Design while the database provider package lags behind.
Related errors
- No files were generated in directory
- The following file(s) already exist in directory
- Unable to find expected assembly attribute…
- A type-qualified method call requires an instance…
- Cannot scaffold C# literals of type
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/ac701f7f849ab274.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs:103
}
else if (!codeOptions.SuppressOnConfiguring)
{
_reporter.WriteWarning(DesignStrings.SensitiveInformationWarning);
}
codeOptions.ConnectionString ??= connectionString;
var databaseModel = _databaseModelFactory.Create(resolvedConnectionString, databaseOptions);
var modelConnectionString = (string?)databaseModel[ScaffoldingAnnotationNames.ConnectionString];
if (!string.IsNullOrEmpty(modelConnectionString))
{
codeOptions.ConnectionString = modelConnectionString;
}
var model = _factory.Create(databaseModel, modelOptions);
if (model == null)
{
throw new InvalidOperationException(
DesignStrings.ProviderReturnedNullModel(
_factory.GetType().ShortDisplayName()));
}
if (string.IsNullOrEmpty(codeOptions.ContextName))
{
var annotatedName = model.GetDatabaseName();
codeOptions.ContextName = !string.IsNullOrEmpty(annotatedName)
? _code.Identifier(annotatedName + DbContextSuffix)
: DefaultDbContextName;
}
var codeGenerator = ModelCodeGeneratorSelector.Select(codeOptions);
return codeGenerator.GenerateModel(model, codeOptions);
}
/// <summary>View on GitHub (pinned to 3a2006ef56)