{"record":{"id":"d67fa0c45e4c5b4a","repo":"dotnet/efcore","slug":"usechangetrackingproxies-and-uselazyloadingprox-d67fa0","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/ProxyFactory.cs","lineNumber":78,"sourceCode":"            entityType.ClrType,\n            GetInterfacesToProxy(entityType),\n            GenerationOptions);\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 object CreateLazyLoadingProxy(\n        DbContext context,\n        IEntityType entityType,\n        ILazyLoader loader,\n        object[] constructorArguments)\n    {\n        var options = context.GetService<IDbContextOptions>().FindExtension<ProxiesOptionsExtension>();\n        return options == null\n            ? throw new InvalidOperationException(ProxiesStrings.ProxyServicesMissing)\n            : CreateLazyLoadingProxy(entityType, loader, constructorArguments);\n    }\n\n    private object CreateLazyLoadingProxy(\n        IEntityType entityType,\n        ILazyLoader loader,\n        object[] constructorArguments)\n        => _generator.CreateClassProxy(\n            entityType.ClrType,\n            GetInterfacesToProxy(entityType),\n            GenerationOptions,\n            constructorArguments,\n            GetNotifyChangeInterceptors(entityType, new LazyLoadingInterceptor(entityType, loader)));\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","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs#L60-L96","documentation":"Thrown by ProxyFactory.CreateLazyLoadingProxy when IDbContextOptions has no ProxiesOptionsExtension — i.e. neither UseLazyLoadingProxies nor UseChangeTrackingProxies was configured on the DbContext options for this context. The lazy-loading proxy path needs the proxies extension registered in the options pipeline.","triggerScenarios":"CreateLazyLoadingProxy is invoked (typically through internal/proxy-factory code paths) while the context's DbContextOptions were built without calling UseLazyLoadingProxies() or UseChangeTrackingProxies().","commonSituations":"Calling proxy creation directly in test or scaffolding code against a context whose options omit the proxies call; configuring proxies on a different DbContextOptions instance than the one used to construct the context; AddDbContext forgot the options lambda that enables proxies.","solutions":["Call optionsBuilder.UseLazyLoadingProxies() (or UseChangeTrackingProxies) in the DbContext configuration.","Ensure the same DbContextOptions instance that has the proxies extension is passed to the DbContext constructor / AddDbContext.","If using an internal service provider, also call AddEntityFrameworkProxies() on it."],"exampleFix":"// before\noptionsBuilder.UseSqlServer(connStr);\n// later: factory.CreateLazyLoadingProxy(...) throws\n\n// after\noptionsBuilder\n    .UseSqlServer(connStr)\n    .UseLazyLoadingProxies();","handlingStrategy":"validation","validationCode":"// Confirm proxies are configured before invoking lazy-loading proxy creation\nvar ext = context.GetService<IDbContextOptions>().FindExtension<ProxiesOptionsExtension>();\nif (ext == null)\n    throw new InvalidOperationException(\"Call UseLazyLoadingProxies()/UseChangeTrackingProxies() on DbContextOptions.\");\n// safe to create lazy-loading proxy","typeGuard":"static bool ProxiesEnabled(DbContext c)\n    => c.GetService<IDbContextOptions>().FindExtension<ProxiesOptionsExtension>() != null;","tryCatchPattern":null,"preventionTips":["Always call UseLazyLoadingProxies()/UseChangeTrackingProxies() in the options builder.","Use the same options instance for context construction and proxy creation.","Register AddEntityFrameworkProxies() when using a custom internal service provider."],"tags":["ef-core","proxies","lazy-loading","dbcontext-options","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}