{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs#L24-L60","documentation":"Thrown by ProxyFactory.Create when a proxy is requested for a CLR type that the runtime model cannot resolve, but the type is registered as a shared-type entity type. Shared-type entity types (e.g. Dictionary<string, object> keyed by name) do not have a unique CLR type, so EF needs the explicit entity type name to find them.","triggerScenarios":"Calling DbSet/ProxyFactory.Create with only a CLR type that is used as a shared type — context.Model.FindRuntimeEntityType(type) returns null and context.Model.IsShared(type) is true (ProxyFactory.cs:40-42). Common with the many-to-many join entity pattern using Dictionary<string,object>.","commonSituations":"Using shared-type entities (Dictionary-based join tables) and attempting to create a proxy through the Type-based overload instead of the name-based DbSet.Set(string) overload; scaffolding/migration code that iterates types generically.","solutions":["Use the name-based DbSet overload: context.Set(typeof(T).Name, sharedTypeName) or DbContext.Set(Type, string) before calling CreateProxy, so EF knows which shared entity definition to use.","Call CreateProxy via the IEntityType overload (CreateProxy(context, entityType, args)) after resolving the IEntityType by name, instead of the Type overload.","Avoid using shared-type entity types with proxies; map a concrete CLR class for the join entity instead."],"exampleFix":"// before\nvar proxy = context.CreateProxy<Dictionary<string, object>>(args); // throws\n\n// after\nvar entityType = context.Model.FindEntityType(\"MySharedEntity\")!;\nvar proxy = ((IInfrastructure<IServiceProvider>)context)\n    .Instance.GetRequiredService<IProxyFactory>()\n    .CreateProxy(context, entityType, args);","handlingStrategy":"validation","validationCode":"IEntityType? ResolveSharedEntity(DbContext context, Type clrType, string name)\n{\n    var et = context.Model.FindEntityType(name)\n             ?? context.Model.FindRuntimeEntityType(clrType);\n    if (et == null && context.Model.IsShared(clrType))\n        throw new InvalidOperationException($\"Use Set(Type,'{name}') to resolve shared entity.\");\n    return et;\n}","typeGuard":"static bool IsSharedTypeEntity(DbContext context, Type t)\n    => context.Model.IsShared(t);","tryCatchPattern":null,"preventionTips":["Always resolve shared-type entities by name via Set(Type, string) before proxy creation.","Prefer concrete CLR classes for join entities when proxies are required.","Wrap proxy creation in a helper that takes the entity type name for shared types."],"tags":["efcore","proxies","shared-type-entity","entity-not-found"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}