{"record":{"id":"807ce9bcd83060b7","repo":"dotnet/efcore","slug":"the-type-clrtype-is-configured-as-a-shared-typ","errorCode":null,"errorMessage":"The type '{clrType}' is configured as a shared-type entity type, but the entity type name is not known. Ensure that CreateProxy is called on a DbSet created specifically for the shared-type entity type through use of a 'DbContext.Set' overload that accepts an entity type name.","messagePattern":"The type '(.+?)' is configured as a shared-type entity type, but the entity type name is not known\\. Ensure that CreateProxy is called on a DbSet created specifically for the shared-type entity type through use of a 'DbContext\\.Set' overload that accepts an entity type name\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs","lineNumber":42,"sourceCode":"    private readonly ProxyGenerator _generator = new();\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 Create(\n        DbContext context,\n        Type type,\n        params object[] constructorArguments)\n    {\n        var entityType = context.Model.FindRuntimeEntityType(type);\n        if (entityType == null)\n        {\n            if (context.Model.IsShared(type))\n            {\n                throw new InvalidOperationException(ProxiesStrings.EntityTypeNotFoundShared(type.ShortDisplayName()));\n            }\n\n            throw new InvalidOperationException(CoreStrings.EntityTypeNotFound(type.ShortDisplayName()));\n        }\n\n        return CreateProxy(context, entityType, constructorArguments);\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 Type CreateProxyType(\n        IEntityType entityType)\n        => _generator.ProxyBuilder.CreateClassProxyType(\n            entityType.ClrType,","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs#L24-L60","documentation":"Thrown by ProxyFactory.Create when CreateProxy is invoked for a CLR type that is registered as a shared-type entity type (the same CLR type is used by multiple entity types, keyed by name) but no specific entity type name was supplied. FindRuntimeEntityType(type) returns null because the type alone is ambiguous, and IsShared(type) is true. Shared-type entities must be addressed through a named DbSet obtained via the Set(name) overload.","triggerScenarios":"Calling the generic CreateProxy<T> / CreateProxy(serviceProvider, typeof(T), ...) where T is a shared-type entity (e.g. used as a owned/weak type or multiple named entity types sharing one CLR type) without resolving a named DbSet first.","commonSituations":"Using the same CLR class (e.g. a Tag or Address DTO) as several distinct entity types via modelBuilder.Entity<T>(name); trying to materialize a proxy for that CLR type generically; DDD value-object-style reuse of one CLR type across entity types.","solutions":["Obtain the DbSet via the named overload: var set = context.Set<T>(\"EntityName\"); then call CreateProxy on that DbSet.","Call CreateProxy through the DbSet rather than the generic serviceProvider/Type overload so the entity type name is known.","If the type should map to a single entity type, stop configuring it as shared (remove duplicate Entity<T>(name) registrations)."],"exampleFix":"// before: shared-type entity, ambiguous by CLR type alone\nvar proxy = context.CreateProxy<Tag>(); // Tag is shared across named entity types\n\n// after: resolve the named DbSet first\nvar set = context.Set<Tag>(\"OrderTag\");\nvar proxy = set.CreateProxy();","handlingStrategy":"validation","validationCode":"// Resolve a named DbSet for shared-type entities before creating a proxy\nvar entityType = context.Model.FindEntityType(typeof(Tag));\nif (entityType == null && context.Model.IsShared(typeof(Tag)))\n{\n    // Use the named overload instead of the generic CLR-type path\n    var set = context.Set<Tag>(\"OrderTag\");\n    var proxy = set.CreateProxy();\n}\nelse\n{\n    var proxy = context.CreateProxy<Tag>();\n}","typeGuard":"static bool IsSharedType(IModel model, Type t) => model.IsShared(t);","tryCatchPattern":null,"preventionTips":["Use context.Set<T>(name) for any CLR type registered under multiple named entity types.","Avoid reusing one CLR type across several entity types unless necessary.","Document shared-type entity names alongside the CLR type in your model."],"tags":["ef-core","proxies","shared-type-entity","dbset","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}