dotnet/efcore · error · InvalidOperationException

'UseChangeTrackingProxies' and 'UseLazyLoadingProxies' each

Error message

'UseChangeTrackingProxies' and 'UseLazyLoadingProxies' each require 'AddEntityFrameworkProxies' to be called on the internal service provider used.

What it means

ProxiesOptionsExtension.Validate throws ProxyServicesMissing when UseChangeTrackingProxies/UseLazyLoadingProxies is enabled and the configured internal service provider does not contain the ProxiesConventionSetPlugin (ProxiesOptionsExtension.cs:164-177). This happens when AddEntityFrameworkProxies() was not called on the internal service provider in use.

Source

Thrown at src/EFCore.Proxies/Proxies/Internal/ProxiesOptionsExtension.cs:173

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual void Validate(IDbContextOptions options)
    {
        if (UseProxies)
        {
            var internalServiceProvider = options.FindExtension<CoreOptionsExtension>()?.InternalServiceProvider;
            if (internalServiceProvider != null)
            {
                using var scope = internalServiceProvider.CreateScope();
                var conventionPlugins = scope.ServiceProvider.GetService<IEnumerable<IConventionSetPlugin>>();
                if (conventionPlugins?.Any(s => s is ProxiesConventionSetPlugin) == false)
                {
                    throw new InvalidOperationException(ProxiesStrings.ProxyServicesMissing);
                }
            }
        }
    }

    /// <summary>
    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
    ///     any release. You should only use it directly in your code with extreme caution and knowing that
    ///     doing so can result in application failures when updating to a new Entity Framework Core release.
    /// </summary>
    public virtual void ApplyServices(IServiceCollection services)
        => services.AddEntityFrameworkProxies();

    private sealed class ExtensionInfo(IDbContextOptionsExtension extension) : DbContextOptionsExtensionInfo(extension)
    {
        private string? _logFragment;

View on GitHub (pinned to dbf9771522)

Solutions

  1. Call AddEntityFrameworkProxies() on the IServiceCollection used to build the internal service provider (before UseInternalServiceProvider).
  2. Stop using a custom internal service provider and let EF build its own, which will include proxy services automatically when you call UseLazyLoadingProxies/UseChangeTrackingProxies.

Example fix

// before
var services = new ServiceCollection();
services.AddDbContextPool<AppDb>(o => o.UseLazyLoadingProxies());
services.AddDbContext<OtherDb>(o => o.UseInternalServiceProvider(services.BuildServiceProvider()));
// after
var services = new ServiceCollection();
services.AddEntityFrameworkProxies();
services.AddDbContextPool<AppDb>(o => o.UseLazyLoadingProxies());
Defensive patterns

Strategy: validation

Validate before calling

// When using a shared internal service provider with proxies, register proxy services:
var services = new ServiceCollection();
services.AddEntityFrameworkProxies();
services.AddDbContext<AppDb>(o =>
{
    o.UseInternalServiceProvider(services.BuildServiceProvider());
    o.UseLazyLoadingProxies();
});

Prevention

When it happens

Trigger: Using UseInternalServiceProvider(...) (pooling or a shared provider) together with UseLazyLoadingProxies()/UseChangeTrackingProxies() but forgetting to call AddEntityFrameworkProxies() when building that shared provider.

Common situations: Using AddDbContextPool or AddDbContext with UseInternalServiceProvider and enabling proxies without registering proxy services on the shared IServiceCollection.

Related errors


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