C
C#2y ago
Angius

❔ Return gets ignored for some godforsaken reason

Despite the if (cb is null) return NotFound(); the code progresses further, and causes an unhandled exception
40 Replies
333fred
333fred2y ago
Use a debugger
Angius
Angius2y ago
I am The screenshot comes from the debugger, in fact
333fred
333fred2y ago
Well, what happens when you step through the method?
Angius
Angius2y ago
Angius
Angius2y ago
GetClubBar()? It returns null Which should trigger the return NotFound() But... doesn't
333fred
333fred2y ago
I mean, being entirely honest: I don't believe you If a basic is null check was broken, the world would be on fire Set a breakpoint on that if check and see what cb is at that point
Angius
Angius2y ago
You can see it in the screenshot, the inline value, cb is null
333fred
333fred2y ago
Set a breakpoint and see what the value is when the check actually occurs Given that this is an async method, you're past an await barrier, and cb being lifted to a field, it would not surprise me if rider's debugger was lying to you in some fashion where you are right now
Angius
Angius2y ago
Uh, huh, it seems if I place the breakpoint there it never gets hit...? Nor when I place a breakpoint anywhere after Never hits the return of my GetClubBar() method either... so something earlier What, though...
333fred
333fred2y ago
Alright, so probably this screenshot is a broken state of something
Angius
Angius2y ago
Could be
Angius
Angius2y ago
Line 27 bp gets hit, like 49 bp doesn't
Angius
Angius2y ago
So something with the EF query Wtf does Nullable object must have a value mean tho Isn't the purpose of nullable objects that they can not have a value...?
333fred
333fred2y ago
Which of the things that you unconditionally dereference are nullable value types? Or possibly reference types, not sure how that error gets reported from an EF query
Angius
Angius2y ago
// Club.cs
public class Club : BaseModel, IReportableContent
{
public required string Name { get; set; }
public required string Slug { get; set; }
public required string Hook { get; set; }
public required string Description { get; set; }
public required string Icon { get; set; }
public required string IconId { get; set; }
public DateTime CreationDate { get; set; }
public ICollection<ClubMember> ClubMembers { get; set; } = new List<ClubMember>();
public ICollection<OgmaUser> BannedUsers { get; set; } = new List<OgmaUser>();
public ICollection<ClubThread> Threads { get; set; } = new List<ClubThread>();
public ICollection<Folder> Folders { get; set; } = new List<Folder>();
public ICollection<Report> Reports { get; set; } = new List<Report>();
}
// Club.cs
public class Club : BaseModel, IReportableContent
{
public required string Name { get; set; }
public required string Slug { get; set; }
public required string Hook { get; set; }
public required string Description { get; set; }
public required string Icon { get; set; }
public required string IconId { get; set; }
public DateTime CreationDate { get; set; }
public ICollection<ClubMember> ClubMembers { get; set; } = new List<ClubMember>();
public ICollection<OgmaUser> BannedUsers { get; set; } = new List<OgmaUser>();
public ICollection<ClubThread> Threads { get; set; } = new List<ClubThread>();
public ICollection<Folder> Folders { get; set; } = new List<Folder>();
public ICollection<Report> Reports { get; set; } = new List<Report>();
}
// ClubBar.cs
public class ClubBar
{
public required long Id { get; set; }
public required string Name { get; set; }
public required string Slug { get; set; }
public required string Hook { get; set; }
public required string Description { get; set; }
public required string Icon { get; set; }
public required DateTime CreationDate { get; set; }
public required int ClubMembersCount { get; set; }
public required int ThreadsCount { get; set; }
public required int StoriesCount { get; set; }
public bool IsMember => Role is not null;
public required long FounderId { get; set; }
public required EClubMemberRoles? Role { get; set; }
}
// ClubBar.cs
public class ClubBar
{
public required long Id { get; set; }
public required string Name { get; set; }
public required string Slug { get; set; }
public required string Hook { get; set; }
public required string Description { get; set; }
public required string Icon { get; set; }
public required DateTime CreationDate { get; set; }
public required int ClubMembersCount { get; set; }
public required int ThreadsCount { get; set; }
public required int StoriesCount { get; set; }
public bool IsMember => Role is not null;
public required long FounderId { get; set; }
public required EClubMemberRoles? Role { get; set; }
}
Nothing really jumps out at me Okay, I'm getting somewhere...
.Select(c => new ClubBar
{
Id = c.Id,
Name = c.Name,
Slug = c.Slug,
Hook = c.Hook,
Description = c.Description,
Icon = c.Icon,
CreationDate = c.CreationDate,
ThreadsCount = 0, //, c.Threads.Count,
ClubMembersCount = 0,// c.ClubMembers.Count,
StoriesCount = 0,// c.Folders.Sum(f => f.StoriesCount),
FounderId = 7,// c.ClubMembers.First(cm => cm.Role == EClubMemberRoles.Founder).MemberId,
Role = null
// c.ClubMembers.Any(cm => cm.MemberId == _uid)
// ? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
// : null
})
.Select(c => new ClubBar
{
Id = c.Id,
Name = c.Name,
Slug = c.Slug,
Hook = c.Hook,
Description = c.Description,
Icon = c.Icon,
CreationDate = c.CreationDate,
ThreadsCount = 0, //, c.Threads.Count,
ClubMembersCount = 0,// c.ClubMembers.Count,
StoriesCount = 0,// c.Folders.Sum(f => f.StoriesCount),
FounderId = 7,// c.ClubMembers.First(cm => cm.Role == EClubMemberRoles.Founder).MemberId,
Role = null
// c.ClubMembers.Any(cm => cm.MemberId == _uid)
// ? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
// : null
})
zeroing out everything made it work Lemme uncomment those one by one
333fred
333fred2y ago
I wonder if ClubMembers is null Mainly because I see it a bunch there
Angius
Angius2y ago
Uncommented everything down to Role and it works lmao At least with quick reload But I also do see the data actually show up Issue seems to be somewhere her
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: null
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: null
Since uncommenting it broke the site again
333fred
333fred2y ago
Well, return null from the first branch See if it's the call to Role Or could MemberId be null? You didn't share that model definition
Angius
Angius2y ago
public class ClubMember
{
public OgmaUser Member { get; init; }
public long MemberId { get; init; }
public Club Club { get; init; }
public long ClubId { get; init; }
public EClubMemberRoles Role { get; init; }
public DateTime MemberSince { get; init; }
}
public class ClubMember
{
public OgmaUser Member { get; init; }
public long MemberId { get; init; }
public Club Club { get; init; }
public long ClubId { get; init; }
public EClubMemberRoles Role { get; init; }
public DateTime MemberSince { get; init; }
}
It's a long so unlikely
333fred
333fred2y ago
Is EClubMemberRoles a reference type?
Angius
Angius2y ago
An enum
333fred
333fred2y ago
Hmm Try casting the first branch of the ternary to a EClubMemberRoles?
Angius
Angius2y ago
333fred
333fred2y ago
Ignore the warning And see if that fixes it
Angius
Angius2y ago
No cigar
333fred
333fred2y ago
What about removing the null from the other branch And using default(EClubMemberRoles)
Angius
Angius2y ago
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: EClubMemberRoles.User
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: EClubMemberRoles.User
no cigar either
333fred
333fred2y ago
Did you try this?
Angius
Angius2y ago
Yeah, also errors out for some reason
333fred
333fred2y ago
With the same error?
Angius
Angius2y ago
Maybe it's the fault of hot reload, lemme restart the whole thing
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? null // c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: default
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? null // c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: default
doesn't work
333fred
333fred2y ago
I wouldn't use default there
Angius
Angius2y ago
333fred
333fred2y ago
It's not clear what type it binds to Use default(TheActualTypeYouWant)
Angius
Angius2y ago
Ah, huh... I brought everything back to this state and it doesn't work It seems the issue might lie in the FounderID...? When I set the role to null and founder ID is as it is, it errors When I hardcode 7 or something to it, it works Yeah
.Select(c => new ClubBar
{
Id = c.Id,
Name = c.Name,
Slug = c.Slug,
Hook = c.Hook,
Description = c.Description,
Icon = c.Icon,
CreationDate = c.CreationDate,
ThreadsCount = c.Threads.Count,
ClubMembersCount = c.ClubMembers.Count,
StoriesCount = c.Folders.Sum(f => f.StoriesCount),
FounderId = 7,// c.ClubMembers.First(cm => cm.Role == EClubMemberRoles.Founder).MemberId,
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: null
})
.Select(c => new ClubBar
{
Id = c.Id,
Name = c.Name,
Slug = c.Slug,
Hook = c.Hook,
Description = c.Description,
Icon = c.Icon,
CreationDate = c.CreationDate,
ThreadsCount = c.Threads.Count,
ClubMembersCount = c.ClubMembers.Count,
StoriesCount = c.Folders.Sum(f => f.StoriesCount),
FounderId = 7,// c.ClubMembers.First(cm => cm.Role == EClubMemberRoles.Founder).MemberId,
Role = c.ClubMembers.Any(cm => cm.MemberId == _uid)
? c.ClubMembers.First(cm => cm.MemberId == _uid).Role
: null
})
this works
333fred
333fred2y ago
So you have a club with no founder? Might be best to break out a DB explorer and see what data you have
Angius
Angius2y ago
Shit Seems to be the case, yeah Club with ID 1 somehow ended up without a founder
333fred
333fred2y ago
Oops At least we figured that out
Angius
Angius2y ago
Yeah lol How did I get to this state, though... I hate it when projects grow large enough for me to get lost lol
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server
More Posts
✅ [RESOLVED]It seems that my variables is destroyed after the Awake()Hello, I’m trying to accessing a variable from another script with a singleton. When I debug the var❔ ✅ gettext amount always Underlined as red and not working in the codegettext amount are always Underlined as red and not working in my ui CodecodeUnresolved NuGet Dependency ReferencesI have XUnit added as a dependency to my test project via NuGet. Despite this, my test project code ❔ UNITY Code only fully executes after running it another timeWhen running GenerateCities() it only does DestroyCities() and CreateCountryColors() before stopping✅ Recieve less than transmitting in network streamHello there, I'm trying to implement a FTP server and I got troubles with the network stream Whenevedouble.Parse(3.5).ToString() returns 35I got confused troubleshooting since web results didnt help, so i asked chatgpt and his code snippet❔ How could I make my console app not close when it's double clicked in explorer?my console app is directed towards beginners (supposed to work alongside an existing app, which is a❔ Authorization handling in asp.net coreHey, in asp.net core you can use Authorization Handlers and Type Filters to authorize a request. Th❔ Is there an equivalent feature to TypeScript's Indexed Access Types?e.g. ```ts type Example<T> = { items: T[] } type StringItems = Example<string>["items"] // stringA series of errors (Install failed & Minimal hosting scenario!) while scaffolding for a ASP.NET CoreI followed this instruction to execute the ```API Controller with views, using Entity Framework``` h