C
C#Lamp

ASP.NET Identity Login Error

When trying to sign in using SignInManager, I get a SqlException: Invalid column name 'UserId1'. Why is there an extra user column being added to the query? My extended identity classes are listed below.
var result = await _signInManager.PasswordSignInAsync(
user,
Input.Password,
Input.RememberMe,
lockoutOnFailure: false
);
var result = await _signInManager.PasswordSignInAsync(
user,
Input.Password,
Input.RememberMe,
lockoutOnFailure: false
);
public class ApplicationUser : IdentityUser
{
[Required(ErrorMessage = "First name is required")]
[Display(Name = "First Name")]
[MaxLength(50)]
public string FirstName { get; set; }

[Required(ErrorMessage = "Last name is required")]
[Display(Name = "Last Name")]
[MaxLength(50)]
public string LastName { get; set; }

public virtual ICollection<ApplicationUserClaim> Claims { get; set; }

public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }

public virtual ICollection<IdentityUserToken<string>> Tokens { get; set; }
}

public class ApplicationRole : IdentityRole
{
}

public class ApplicationUserRole : IdentityUserRole<string>
{
public bool IsReadOnly { get; set; }

public string ProgramId { get; set; }

public bool IsDefault { get; set; }

public virtual TestProgram Program { get; set; }
}

public class ApplicationRoleClaim : IdentityRoleClaim<string>
{
public virtual ApplicationRole Role { get; set; }
}

public class ApplicationUserClaim : IdentityUserClaim<string>
{
public virtual ApplicationUser User { get; set; }
}

public partial class ApplicationDbContext : IdentityDbContext<
ApplicationUser, ApplicationRole, string,
ApplicationUserClaim, ApplicationUserRole, IdentityUserLogin<string>,
ApplicationRoleClaim, IdentityUserToken<string>>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

/// DbSets

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
public class ApplicationUser : IdentityUser
{
[Required(ErrorMessage = "First name is required")]
[Display(Name = "First Name")]
[MaxLength(50)]
public string FirstName { get; set; }

[Required(ErrorMessage = "Last name is required")]
[Display(Name = "Last Name")]
[MaxLength(50)]
public string LastName { get; set; }

public virtual ICollection<ApplicationUserClaim> Claims { get; set; }

public virtual ICollection<IdentityUserLogin<string>> Logins { get; set; }

public virtual ICollection<IdentityUserToken<string>> Tokens { get; set; }
}

public class ApplicationRole : IdentityRole
{
}

public class ApplicationUserRole : IdentityUserRole<string>
{
public bool IsReadOnly { get; set; }

public string ProgramId { get; set; }

public bool IsDefault { get; set; }

public virtual TestProgram Program { get; set; }
}

public class ApplicationRoleClaim : IdentityRoleClaim<string>
{
public virtual ApplicationRole Role { get; set; }
}

public class ApplicationUserClaim : IdentityUserClaim<string>
{
public virtual ApplicationUser User { get; set; }
}

public partial class ApplicationDbContext : IdentityDbContext<
ApplicationUser, ApplicationRole, string,
ApplicationUserClaim, ApplicationUserRole, IdentityUserLogin<string>,
ApplicationRoleClaim, IdentityUserToken<string>>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}

/// DbSets

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
P
Pobiega39d ago
Have you created and ran the migrations?
L
Lamp39d ago
yes i have, my db matches that i mentioned it happening with PasswordSignInAsync() but honestly it keeps happening with almost any method related to those tables
L
Lamp39d ago
No description
L
Lamp39d ago
oops turns out i hadnt
P
Pobiega39d ago
:when:
L
Lamp39d ago
how do i get it to work tho like the migration error
P
Pobiega39d ago
No description
P
Pobiega39d ago
You tell me.
L
Lamp39d ago
fuck enchantment table errors one moment omg it wont let me copy the text
L
Lamp39d ago
No description
L
Lamp39d ago
is that any better
P
Pobiega39d ago
Well it's readable, but none of those are errors
L
Lamp39d ago
wait so why is there an X
P
Pobiega39d ago
Is that all the text? Also... Ef power tools? Wtf is that
L
Lamp39d ago
GitHub
GitHub - ErikEJ/EFCorePowerTools: Entity Framework Core Power Tools...
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI - ErikEJ/EFCorePowerTools
L
Lamp39d ago
everyone uses it theres so much i cant fit it on my screen and the window isnt resizeable lmao the migration tool is in preview still ig so i should probably do it via command line?
P
Pobiega39d ago
thats distinctly not true, as I've never heard of it before :p dotnet ef is all you need
L
Lamp39d ago
ok
P
Pobiega39d ago
also, uhhh EF7? why does it say EF7 in several places what .NET version are you using on this project? And what packagereference version is your EF package?
L
Lamp39d ago
.net 8 also that repo isnt mine i just wanted to give u more info on the tool i was using so ignore the ef7 thing
P
Pobiega39d ago
Ah right, its the preview thingy
L
Lamp39d ago
but yea im using .net8 with razor pages Microsoft.Data.SqlClient.SqlException (0x80131904): There is already an object named 'TestTypes' in the database. i tried doing it via cli but it throws an error on my first table saying it already exists?
J
Jimmacle39d ago
sounds like your migrations are out of sync with your database if there's nothing valuable in the DB just delete it and recreate it
L
Lamp39d ago
ok so i reran the migration command but before i could, it wanted me to update to .net8.0.2, so i did, and now i got this in the console and my app wont even open in the browser now lmfaoo
P
Pobiega39d ago
Why are you uploading text? Just paste it.
L
Lamp39d ago
i did it auto did that
P
Pobiega39d ago
If it's too long, use pastebin Opening txt files on a phone is not a fun experience
L
leowest39d ago
because of the cahracter size
L
Lamp39d ago
Pastebin
[10:55:14 DBG] An 'IServiceProvider' was created for internal use b...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
L
leowest39d ago
BlazeBin - bhtelnoscqgm
A tool for sharing your source code with the world!
L
Lamp39d ago
lol sorry about that
L
leowest39d ago
its not your fault, its just that its too long so discord automatically converts it to a file
L
Lamp39d ago
yea i hate it when it does that XD
L
leowest39d ago
I blame Pobiega :madcar:
P
Pobiega39d ago
Wtf Ok I'm at a bathhouse so Leo, congratulations I appoint you in charge of this
L
Lamp39d ago
ok anyway so clearly my models are fucked if theres all these shadow properties right
L
leowest39d ago
well I dont know Identity so lets see @Lamp where u deploying these to? local db or what
L
Lamp39d ago
sql server
L
leowest39d ago
and did u dump the db before running migrations again given what macle said, if u dont have anything of value in it
P
Pobiega39d ago
Those errors are from generating the migration, no? It sure look like it
L
Lamp39d ago
ahh, it is kinda valuable unfortunately
P
Pobiega39d ago
Are you adding identity to an existing database?
L
leowest39d ago
and u should have scaffolded the db models not create a new one on top
L
Lamp39d ago
ok so long story short, i got hired recently, boss is in the hospital (2 person team) so i cant ask him, he just handed me a "copy" of the db that i can use locally along with the app he was working on afaik we're using the individual accounts razor pages template just with a bunch of our own stuff built on top
L
Lamp39d ago
and i believe the db started out with identity, like all the AspNetUsers, AspNetRoles, etc are there
No description
J
Jimmacle39d ago
are you sure the version of the code you're using matches what is compatible with the DB you were given? that sounds more like you were given 2 things that didn't work together to begin with
L
Lamp39d ago
honestly, no im not entirely sure, however i have used the efcore power tools reverse engineer feature to generate the models and such for me... but when i do that, none of the identity code comes in, i have to manually add that every time
No description
L
Lamp39d ago
ig so far its been "db-first" design?
J
Jimmacle39d ago
what version of identity/ASP.NET generated the database? i don't think db-first is going to work nicely here because the models it would be generating are built into the identity library
L
Lamp39d ago
now that you mention it, that makes a lot of sense
J
Jimmacle39d ago
why are you trying to scaffold an identity database that another application generated anyway?
L
Lamp39d ago
its a relatively new project so its .net8 but where would i check the identity version? i assume its the newest?
J
Jimmacle39d ago
you'd check the code of the application that created this db
L
Lamp39d ago
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.2" /> <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.2" /> yea its the latest one i believe
J
Jimmacle39d ago
is the project you're working on now the same one that "owns" this database or are you trying to pull in data from another application?
L
Lamp39d ago
yes, the project im working on is the same one that owns the db. im like 99% sure of that
J
Jimmacle39d ago
then you shouldn't be scaffolding anything or making any of your own migrations unless you change the models yourself
L
Lamp39d ago
wait, why?
J
Jimmacle39d ago
because the application will already have the migrations it used to get the database to the state it's in now
L
Lamp39d ago
sooo... about that. there are none
J
Jimmacle39d ago
okay, go to the database and look at the __EFMigrationsHistory table
L
Lamp39d ago
its empty and didnt exist (i dont remember seeing it) until i tried to run my own migration
J
Jimmacle39d ago
does the application call .EnsureCreated() anywhere in its startup code or something?
L
Lamp39d ago
no
J
Jimmacle39d ago
so how did the database come to exist in the first place?
L
Lamp39d ago
I assume my boss made it somehow
J
Jimmacle39d ago
yes, the options are either migrations or calling EnsureCreated it should 100% be migrations if you ever planned to change anything about the database if you have no migrations, this was broken before you ever touched it
L
Lamp39d ago
wait is it possible he made it manually then just used the reverse engineer tool to generate the models then manually added the identity dbcontext stuff
J
Jimmacle39d ago
that would be very dumb and unlikely, but technically maybe
L
Lamp39d ago
hmm is there any way for me to fix it?
L
leowest39d ago
that would still make no sense thou he made the app right?
L
Lamp39d ago
yes
J
Jimmacle39d ago
assuming the code you have has the same model that was used to set up the DB, you can create an initial migration and manually record it in the __EFMigrationsHistory table
L
leowest39d ago
so he should have the models right
J
Jimmacle39d ago
so EF won't try to apply it and future migrations will build on it or find someone who can answer why there are no migrations in the codebase
L
Lamp39d ago
ok i did some searching and in the repo we have, his first commit had migrations, however he deleted the folder in the next commit and those would be pretty out of date for how the tables look now so i should just do this?
J
Jimmacle39d ago
they should never have been deleted, they're as important as the rest of the code in the project yeah if they're just gone you should create a new "initial" migration and fake it being applied
L
Lamp39d ago
ok i just did the initial commit
J
Jimmacle39d ago
add a row that looks something like this
No description
J
Jimmacle39d ago
but with your actual migration name
L
Lamp39d ago
i was just going to ask that, lol, thank you!
J
Jimmacle39d ago
assuming the models match the DB then you'll be good, if not you're kind of stuck
L
Lamp39d ago
the name of the file is 20240307155516_InitialCreate.cs, do i need to include the "create" portion?
J
Jimmacle39d ago
yeah just take the .cs off
L
Lamp39d ago
No description
L
Lamp39d ago
good?
J
Jimmacle39d ago
yeah, i don't know what it uses the productversion for so you may have to make that a real EF version but you can try it
L
Lamp39d ago
how would i test that it works?
J
Jimmacle39d ago
this doesn't do anything on its own, it just stops future migrations from trying to create things that already exist
L
Lamp39d ago
ok gotcha
J
Jimmacle39d ago
you've basically synced up what the migration tool thinks the DB currently looks like with what it actually currently looks like (assuming your models matched already)
L
Lamp39d ago
shit new issue, when i installed the ef cli tools, i had to update to .net 8.0.2, and now the app opens in the browser but cant find any of my pages 😭 i didnt even touch anything i updated from 8.0.1 to 8.0.2
J
Jimmacle39d ago
do you have important work on your working branch? if not i'd just roll back to whatever you were initially given, do the migration thing, then go from there
L
Lamp39d ago
sadly yes i 100% fucked up
J
Jimmacle39d ago
either way, i'd start fresh and make that work, then move your changes on top of that check out a fresh copy somewhere else to try fixing
L
Lamp39d ago
a fresh copy of the repo? i assume?
J
Jimmacle39d ago
right then theoretically you can apply your existing commits on it once you've fixed it, minus any scaffolding jank or just copy/paste the code
L
Lamp39d ago
so with that, there really hasnt been a point where the identity stuff worked i mean maybe when the app was created
J
Jimmacle39d ago
as in the deployed version doesn't work either?
L
Lamp39d ago
this app isnt deployed yet, we're trying to get it ready for production soon for queries, most things work, but if its related to identity, it tends to break that's my main issue i've noticed
J
Jimmacle39d ago
so just for fun, use your migration to create a brand new DB and see if things work that way assuming your application can bootstrap itself from a fresh database, which isn't a guarantee at this point :KEKW: if nothing is in prod then the existing data probably isn't that important
L
Lamp39d ago
fair
J
Jimmacle39d ago
and that will at least help you determine whether identity is really broken or someone just messed up the database at some point and never fixed it which is likely if they thought deleting migrations was a good idea
L
Lamp39d ago
wait wdym how would i do that
J
Jimmacle39d ago
i mean if the application code depends on data already being in the database then it will probably not work if the database is brand new only one way to find out, create a db, apply the migration, and see if it works
L
Lamp39d ago
ohh i see before i do that, i need my app to work tho
J
Jimmacle39d ago
this is part of making your app work
L
Lamp39d ago
cause it wont open now
J
Jimmacle39d ago
that's why i'm saying start over and re-apply your code but without the stuff that broke it
L
Lamp39d ago
the only thing that i changed from when it was running to when it broke was updating to .net8.0.2
J
Jimmacle39d ago
(also fwiw you can install specific versions of tools and not update your whole project) then undo that
L
Lamp39d ago
so i didnt update the project i literally installed it from https://dotnet.microsoft.com/en-us/download/dotnet/8.0 *installed .net 8.0.2 apologies i had a meeting CS9057 The analyzer assembly 'C:\Program Files\dotnet\sdk\8.0.201\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.CodeAnalysis.Razor.Compiler.SourceGenerators.dll' references version '4.9.0.0' of the compiler, which is newer than the currently running version '4.8.0.0'.
i noticed this in my error list, but just listed as a warning could that be it? i did this but i just cant test it yet cause the app wont open
J
Jimmacle39d ago
then install the .NET version that worked
L
Lamp39d ago
Ok, literally restarted my pc and its working again lmfao Love that
Want results from more Discord servers?
Add your server
More Posts
How do we read network/handshake messages?Hello friends, I have been given the following task: - I should establish a connection to a WebSockeCan different validation attributed be applied to a field based on the active profile?Hello, In `Development` I would need to apply a different validation attribute to a DTO field, withAndroid Emulatorhow to fix this guys please help me.AS2 over http C# Send message with signature to mendelson server.Hi guys) I am new in this channel. Can you please help me with AS2 over http PKCS#7 .p7s file) Yeah.Persistent error with dotnet cli and installing maui workspaceI've tried time and again now without joy. There is precious little info on this issue out there (onneed tips to improve my logical skills and .net c# skills as I'm a intermediate dev.Hi,I want to improve my logical and .net c# skills so i want please suggest me or guide me about to Issue with Azure AD B2C Custom Domains: Unexpected Redirect Behavior and Domain DependencyHey everyone, I'm hopeful that there are experienced individuals with Azure AD B2C expertise who canNode editor, many operations - how to make it maintainableHi, I'm trying to develop an app with node editor that ideally will provide no code openCV functionacannot close window...Release date of 8.0.3?Hey, I have been struggling with an issue that from what I understand will be solved in 8.0.3. httpRedirecting the native standard output streamI need to call into native code the problem is that it writes some of it's output using stdout. Is iWhere can I find a working library for making a LLVM compiler?I found this library (https://github.com/dotnet/LLVMSharp) that provides extern references for the LCheck value type of extended class instanceI have `BaseClass` and `MyClass : BaseClass`. Using `val is BaseClass` will return true for any obj✅ Am I using NumberFormatInfo properly?I have a list of ca. 400 numbers which I want to convert to percentage strings as part of an endpoin✅ .NET MAUI LayoutI am trying to create a password field with the show icon to the right of the password field, when iGetting an error for an undefined variableHello, I'm a CS major working on a project so I'm still pretty new. I'm getting a CS0165 error on liEnemy following after the player (MONOGAME)Im making a simple game using Monogame in visual studio. I have two sprites drawn on the screen (pinIm having an issue checking for collisions when comparing DateTime objects.I have this function that's supposed to check for collisions with bookings. I am using TimeSpans andclamping how fast a input (as a float) can change.Let’s say my Input X float changes in a amount of time from -1 to 1 (-1, -0.5, 0, 0.5, 1) so as an eIValueResolver won't work with AutoMapperHi guys , hope all of you doing well, I'm recently working on a project where I need to convert a sp