I'm developing a Swagger API which acts as a proxy for the Riot API, for an Angular app I'm creating. I last worked on it last week without any problems. Now, however, my data initializer throws a null exception when trying to start it.
At first, I restarted Visual Studio, then I restarted with admin privileges, and lastly restarted the laptop, no dice. Then checked if it was a certain change I made, rolled back to a random commit from a few weeks ago. Same exception.
So, this exception seemingly started appearing from nowhere. Never saw it happen until today, and I can't get it to go away.
The data initializer (The offending line is marked with a comment, at the bottom):
public class SummonerDataInitializer
{
private readonly SummonerContext context;
private readonly UserManager<User> userManager;
private readonly SummonerRepository summonerRepository;
public SummonerDataInitializer(SummonerContext context, UserManager<User> userManager, SummonerRepository summonerRepository)
{
this.context = context;
this.userManager = userManager;
this.summonerRepository = summonerRepository;
}
public async Task InitializeData()
{
await context.Database.EnsureDeletedAsync();
if (await context.Database.EnsureCreatedAsync())
{
var dashboard = new Dashboard
{
PinnedSummoners = new List<Summoner>
{
await summonerRepository.GetBy("euw", "Jhinstachio"),
await summonerRepository.GetBy("euw", "DracoZar"),
await summonerRepository.GetBy("euw", "TrueMrCrazy"),
await summonerRepository.GetBy("euw", "God of Lunar")
},
LiveGameItems = new List<LiveGameItem>
{
new LiveGameItem
{
Region = "euw",
SummonerName = "Don Arts",
},
new LiveGameItem
{
Region = "euw",
SummonerName = "3250",
},
new LiveGameItem
{
Region = "euw",
SummonerName = "Cboi1",
},
}
};
var user = new User("admin", "admin@admin.com") { EmailConfirmed = true };
await userManager.CreateAsync(user, "P@ssword1");
await userManager.AddClaimAsync(user, new Claim(ClaimTypes.Role, "admin"));
user = await context.Users.SingleAsync(u => u.Email == user.Email);
user.Dashboard = dashboard; // Removing this line fixes the exception
context.Users.Update(user);
await context.SaveChangesAsync();
}
}
}
I don't see how the code can be to blame here to be honest. Sure, it isn't super well-written, and that Wait() is smelly, but everything worked until it decided not to. Similar exceptions online point to nothing relevant in this situation, as far as I've seen.
EDIT: Forgot to mention, I also updated Visual Studio and all NuGet packages in vain.