Error: InvalidOperationException: The instance of entity type 'IdentityUserLogin<string>' cannot be tracked because another instance with the same key value for {'LoginProvider', 'ProviderKey'} is already being tracked. When attaching existing entities, ensure that only one entity instance with a given key value is attached. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the conflicting key values
Solution: When you see this error, chances are that you implemented External login with Google or Microsoft and are trying to test the login functionality. When users log in with an External Provider, asp.net core Identity Model logs data to AspNetUserLogin Table, therefore if the record is created for a user, that user won't be able to use the different email to log because a unique identifier is already mapped to that user.
- To solve this problem, you need to backup the AspNetUserLogins table and truncate the table for testing purposes. Do not do this in a production environment, users won't be able to log in, or worse you could lose the data.
- Make sure that the user you are testing on has not other accounts associated with the logins, Asp.Net Core might have tracked or mapped that userid hence preventing you from successfully testing.