{"record":{"id":"4228159e59b647f9","repo":"dotnet/efcore","slug":"usechangetrackingproxies-and-uselazyloadingprox","errorCode":null,"errorMessage":"'UseChangeTrackingProxies' and 'UseLazyLoadingProxies' each require 'AddEntityFrameworkProxies' to be called on the internal service provider used.","messagePattern":"'UseChangeTrackingProxies' and 'UseLazyLoadingProxies' each require 'AddEntityFrameworkProxies' to be called on the internal service provider used\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Proxies/Proxies/Internal/ProxiesOptionsExtension.cs","lineNumber":173,"sourceCode":"\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual void Validate(IDbContextOptions options)\n    {\n        if (UseProxies)\n        {\n            var internalServiceProvider = options.FindExtension<CoreOptionsExtension>()?.InternalServiceProvider;\n            if (internalServiceProvider != null)\n            {\n                using var scope = internalServiceProvider.CreateScope();\n                var conventionPlugins = scope.ServiceProvider.GetService<IEnumerable<IConventionSetPlugin>>();\n                if (conventionPlugins?.Any(s => s is ProxiesConventionSetPlugin) == false)\n                {\n                    throw new InvalidOperationException(ProxiesStrings.ProxyServicesMissing);\n                }\n            }\n        }\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual void ApplyServices(IServiceCollection services)\n        => services.AddEntityFrameworkProxies();\n\n    private sealed class ExtensionInfo(IDbContextOptionsExtension extension) : DbContextOptionsExtensionInfo(extension)\n    {\n        private string? _logFragment;\n","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Proxies/Proxies/Internal/ProxiesOptionsExtension.cs#L155-L191","documentation":"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.","triggerScenarios":"Using UseInternalServiceProvider(...) (pooling or a shared provider) together with UseLazyLoadingProxies()/UseChangeTrackingProxies() but forgetting to call AddEntityFrameworkProxies() when building that shared provider.","commonSituations":"Using AddDbContextPool or AddDbContext with UseInternalServiceProvider and enabling proxies without registering proxy services on the shared IServiceCollection.","solutions":["Call AddEntityFrameworkProxies() on the IServiceCollection used to build the internal service provider (before UseInternalServiceProvider).","Stop using a custom internal service provider and let EF build its own, which will include proxy services automatically when you call UseLazyLoadingProxies/UseChangeTrackingProxies."],"exampleFix":"// before\nvar services = new ServiceCollection();\nservices.AddDbContextPool<AppDb>(o => o.UseLazyLoadingProxies());\nservices.AddDbContext<OtherDb>(o => o.UseInternalServiceProvider(services.BuildServiceProvider()));\n// after\nvar services = new ServiceCollection();\nservices.AddEntityFrameworkProxies();\nservices.AddDbContextPool<AppDb>(o => o.UseLazyLoadingProxies());","handlingStrategy":"validation","validationCode":"// When using a shared internal service provider with proxies, register proxy services:\nvar services = new ServiceCollection();\nservices.AddEntityFrameworkProxies();\nservices.AddDbContext<AppDb>(o =>\n{\n    o.UseInternalServiceProvider(services.BuildServiceProvider());\n    o.UseLazyLoadingProxies();\n});","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always call AddEntityFrameworkProxies() on the IServiceCollection used for UseInternalServiceProvider when enabling proxies.","With AddDbContextPool/pooling, register AddEntityFrameworkProxies on the shared provider.","Avoid mixing a custom internal service provider with proxies unless proxy services are explicitly registered."],"tags":["ef-core","proxies","configuration","service-provider","di"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}