{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Identity/issues/829","repository_url":"https://api.github.com/repos/aspnet/Identity","labels_url":"https://api.github.com/repos/aspnet/Identity/issues/829/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Identity/issues/829/comments","events_url":"https://api.github.com/repos/aspnet/Identity/issues/829/events","html_url":"https://github.com/aspnet/Identity/issues/829","id":156030829,"number":829,"title":"ASP.NET identity configuration exception and that breaks dotnet.exe run process","user":{"login":"mdmoura","id":372865,"avatar_url":"https://avatars.githubusercontent.com/u/372865?v=3","gravatar_id":"","url":"https://api.github.com/users/mdmoura","html_url":"https://github.com/mdmoura","followers_url":"https://api.github.com/users/mdmoura/followers","following_url":"https://api.github.com/users/mdmoura/following{/other_user}","gists_url":"https://api.github.com/users/mdmoura/gists{/gist_id}","starred_url":"https://api.github.com/users/mdmoura/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mdmoura/subscriptions","organizations_url":"https://api.github.com/users/mdmoura/orgs","repos_url":"https://api.github.com/users/mdmoura/repos","events_url":"https://api.github.com/users/mdmoura/events{/privacy}","received_events_url":"https://api.github.com/users/mdmoura/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2016-05-20T19:07:36Z","updated_at":"2016-05-31T22:08:48Z","closed_at":"2016-05-23T15:58:09Z","body":"I am moving a project from ASP.NET Core RC1 to ASP.NET Core RC2 and I have the entities:\r\n\r\n    public class User : IdentityUser<Int32> { }\r\n\r\n    public class Role : IdentityRole<Int32> { }\r\n\r\nOn startup ConfigureServices I have the following as I had in RC1:\r\n\r\n      services.AddIdentity<User, Role>()\r\n          .AddEntityFrameworkStores<Context>()\r\n          .AddDefaultTokenProviders();\r\n\r\nIt builds fine but when I run the project I get an exception and dotnet.exe shuts down:\r\n\r\n`\r\nUnhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: GenericArguments[0], \"WebApp.Entities.User\", on \"Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore \"3[TUser,TRole,TContext]\" violates the constraint of type \"TUser\". ---> System.TypeLoadException: GenericArguments[0], \"WebApp.Entities.User\", on \"Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore \"4[TUser,TRole,TContext,TKey]\" violates the constraint of type parameter \"TUser\".\r\n   at System.RuntimeTypeHandle.Instantiate(RuntimeTypeHandle handle, IntPtr* pInst, Int32 numGenericArgs, ObjectHandleOnStack type)\r\n   at System.RuntimeTypeHandle.Instantiate(Type[] inst)\r\n   at System.RuntimeType.MakeGenericType(Type[] instantiation)\r\n   --- End of inner exception stack trace ---\r\n   at System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)\r\n   at System.RuntimeType.MakeGenericType(Type[] instantiation)\r\n   at Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.GetDefaultServices(Type userType, Type roleType, Type contextType, Type keyType)\r\n   at Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddEntityFrameworkStores[TContext](IdentityBuilder builder)\r\n   at WebApp.Startup.ConfigureServices(IServiceCollection services)\r\n   --- End of inner exception stack trace ---\r\n   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)\r\n   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)\r\n   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)\r\n   at Microsoft.AspNetCore.Hosting.Startup.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection exportServices)\r\n   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()\r\n   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()\r\n   at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()\r\n   at WebApp.Program.Main(String[] args)\r\n`\r\n\r\nAm I missing something?\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/Identity/issues/comments/222836283","html_url":"https://github.com/aspnet/Identity/issues/829#issuecomment-222836283","issue_url":"https://api.github.com/repos/aspnet/Identity/issues/829","id":222836283,"user":{"login":"pachecosoftware","id":11728972,"avatar_url":"https://avatars.githubusercontent.com/u/11728972?v=3","gravatar_id":"","url":"https://api.github.com/users/pachecosoftware","html_url":"https://github.com/pachecosoftware","followers_url":"https://api.github.com/users/pachecosoftware/followers","following_url":"https://api.github.com/users/pachecosoftware/following{/other_user}","gists_url":"https://api.github.com/users/pachecosoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/pachecosoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pachecosoftware/subscriptions","organizations_url":"https://api.github.com/users/pachecosoftware/orgs","repos_url":"https://api.github.com/users/pachecosoftware/repos","events_url":"https://api.github.com/users/pachecosoftware/events{/privacy}","received_events_url":"https://api.github.com/users/pachecosoftware/received_events","type":"User","site_admin":false},"created_at":"2016-05-31T22:08:48Z","updated_at":"2016-05-31T22:08:48Z","body":"When using the 1.0.0-rc3-21101 nightly build, I am getting this same error even when using string as the TKey generic argument of IdentityUser, but only in cases where my ApplicationUser class explicitly extends `IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>` rather than `IdentityUser<TKey>`.\r\n\r\nIn order words, everything works fine when my ApplicationUser class is defined as follows:\r\n\r\n`public class ApplicationUser : IdentityUser<string> { ... }`\r\n\r\nbut when the ApplicationUser class is defined like this:\r\n\r\n`public class ApplicationUser : IdentityUser<string, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>> { ... }`\r\n\r\nthe following error occurs at runtime only (but not at compilation):\r\n\r\n```\r\nGenericArguments[0], 'MyWeb.Models.ApplicationUser', on 'Microsoft.AspNetCore.Identity.EntityFrameworkCore.UserStore`4[TUser,TRole,TContext,TKey]' violates the constraint of type 'TUser'.\r\nat System.RuntimeType.ValidateGenericArguments(MemberInfo definition, RuntimeType[] genericArguments, Exception e)\r\nat System.RuntimeType.MakeGenericType(Type[] instantiation)\r\nat Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.GetDefaultServices(Type userType, Type roleType, Type contextType, Type keyType)\r\nat Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddEntityFrameworkStores<TContext, TKey>(IdentityBuilder builder)\r\nat MyWeb.Startup.ConfigureServices(IServiceCollection services)\r\n```\r\n\r\nOriginally, I was using a Guid type for the key and providing my own implementations for each of the Identity role, claim and login classes, but I rolled everything back to just use all of the standard implementations as shown above to make sure that there wasn't something in my code that was causing the issue, but it made no difference.  \r\n\r\nMy Startup.cs contains the following:\r\n```\r\n        services.AddIdentity<ApplicationUser, IdentityRole<string>>()\r\n                .AddEntityFrameworkStores<ApplicationDbContext, string>()\r\n                .AddDefaultTokenProviders();\r\n```\r\n\r\nBased on the stack trace, and looking through the code, it seems that `Microsoft.Extensions.DependencyInjection.IdentityEntityFrameworkBuilderExtensions.AddEntityFrameworkStores<TContext, TKey>()` is then invoking `GetDefaultServices(),` whose implementation attempts to instantiate a new `UserStore<TUser, TRole, TContext, TKey`>, rather than a new `UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>`.  The  version of the UserStore with only four generic arguments assumes that TUser will be an instance of `IdentityUser<TKey>`, not `IdentityUser<TKey, TUserClaim, TUserRole, TUserLogin>`, and it seems that perhaps this is causing the issue.\r\n\r\nI tried to create my own implementation of` UserStore<TUser, TRole, TContext, TKey, TUserClaim, TUserRole, TUserLogin, TUserToken>` called MyUserStore and modified the Startus.cs as follows:\r\n\r\n```\r\n        services.AddIdentity<ApplicationUser, IdentityRole<string>>()\r\n                .AddEntityFrameworkStores<ApplicationDbContext, string>()\r\n                .AddUserStore<MyUserStore>()\r\n                .AddDefaultTokenProviders();\r\n```\r\n\r\nHowever, that also made no difference, as it looks like AddEntityFrameworkStores() attempts to load up the default implementation before it tries to replace it with my implementation.\r\n\r\nMy ultimate goal is to be able to create my own implementation of the various Identity classes to support a custom multi-tenant configuration, but this error is preventing me from making any progress on that front.  Any light you could shed would be greatly appreciated.  I do have an example zipped up, but I was not able to attach it here for some reason."}}
{"actor":{"display_login":"pachecosoftware"}}