1

Okay, not too sure where I messed up here.

  • MVC 5
  • DotNet 4.5.2
  • Identity 2 extended by BrockAllen IdentityReboot
  • A bunch of other shit.

So I have a Regions table tied into the Users table (AspNetUsers), and because Identity comes with all of its own stuff already scaffolded out, I tried to scaffold out a new “page” to handle assigning regions to users. Well I think that was mistake number one.

I created a Controller and all associated razor views from the ApplicationUser Model class (AFAIR). Attempting to reach the page gave me the error in the title. Nothing I could do seemed to fix the problem. So I ended up deleting the controller and razor views. Problem is, now my ENTIRE SITE in terms of logged-in content is throwing the same error.

Yeah, so I have deliverables in five days, and I think I just hosed my whole project. I can get to the pre-login pages, but anything post-login, including login validation, craps out with the same message.

As an example, an attempt to log on will produce the following:

Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'CCS.Models.ApplicationUser'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Multiple object sets per type are not supported. The object sets 'ApplicationUsers' and 'Users' can both contain instances of type 'CCS.Models.ApplicationUser'.

Source Error: 


Line 61:       // To enable password failures to trigger lockout, change to shouldLockout: true
Line 62:       //var user = await UserManager.FindByEmailAsync(model.Email);
Line 63:       var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);
Line 64:       switch(result) {
Line 65:    case SignInStatus.Success:

Source File: D:\WebDevelopment\CCS\CCS\Controllers\AccountController.cs    Line: 63 

Oh no! I can’t even log in to the application. And no, I do not recall changing anything outside of that single generated controller and razor views. Everything just suddenly went bad. Should I have deleted the controller and razor views in another way? I have also shut VS 2015 down and started it back up, no change. Hell, even the VS console is throwing the error.

Please ask for any code you might need to look at.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
René Kåbis
  • 842
  • 2
  • 9
  • 28

1 Answers1

0

Oh, FFS. Turns out that the answer has been staring me in the face all evening.

A helpful hint for those who come after me: Go to IdentityModel.cs, CTRL+F yourself up a search field, and put in DbSet as your search term. If you are using VS 2015 (and assuming default settings), your scroll bar on the right will show orange paint wherever there is a hit on DbSet.

One group of dots (probably contiguous) will be the actual models that you have manually created. But there will be one or more outliers that will have been auto-generated by the scaffolding, and which will look considerably different than the rest.

For example, my manually created entries look like this:

public DbSet<Province> Province { get; set; }

But the auto-generated entry (that needs deleting / commenting out) looks like this:

public System.Data.Entity.DbSet<CCS.Models.ApplicationUser> ApplicationUsers { get; set; }

Yeah, big difference. And no wonder I couldn’t see it before. I just wasn’t recognizing what I was looking at. Plus, if your public class ApplicationDbContext is filled with a lot of stuff, it will be waaaayyyyy down at the bottom. It gets created at the very end of that class.

Joyous rapture.

Community
  • 1
  • 1
René Kåbis
  • 842
  • 2
  • 9
  • 28