Random things of a random world

Sami's Page

  • Join Us on Facebook!
  • Follow Us on Twitter!
  • LinkedIn
  • Subcribe to Our RSS Feed

ASP.NET Core RC1 to RC2

Phew. That was a ride. I began a new web application on ASP.NET Core RC1 since I like to live on the bleeding edge sometimes. Sometimes it's nice. Sometimes it bites back. Usually RC level stuff is quite stable, but boy wasn't that the case now. So many things changed!

I tried to update packages from RC1 to RC2 by editing project.json but there were so many naming changes that it just didn't work. I ended up creating a new web application with RC2 and copying the packages from there.

One thing that I had to add was the platform info

"Microsoft.NETCore.App": {
"version": "1.0.0-rc2-3002702",
  "type": "platform"

Without this I started getting strange errors on package restore saying Win10-x64 platform isn't supported.

Otherwise the main thing is this: if you have any Microsoft.AspNet packages, get rid of them. If anything says RC1, remove it. They're old. New ones will be named Microsoft.AspNetCore. Entity Framework has moved to Microsoft.EntityFrameworkCore now. No more EntityFramework7.Npgsql, say hello to Npgsql.Entityframework.PostgreSQL.

Better fix all namespace references also. Quite quick find&replace in files from Visual Studio does it, plus probably a couple of manual fixes after.

Startup file has also changed. You'll have to write a bit more stuff in Main, but that's explained at MSDN blog post. But also the way to handle Facebook and EF configuration has changed.

Facebook used to have the typcial lambda, but no more it seems:

app.UseFacebookAuthentication(new FacebookOptions
  AppId = Configuration["Authentication:Facebook:AppId"],
    AppSecret = Configuration["Authentication:Facebook:AppSecret"]

Not a big change but still a bit strange. Others have kept their lambda style still.

Using Npgsql for Identity also changed a bit:

.AddDbContext<ApplicationDbContext>(options =>

Previously you had to add EF and then Npgsql, now it's one call.

The next thing that was a bit baffling was the ApplicationDbContext. Errors about not setting a provider etc. You have to make sure you have a constructor defined like this:

public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)

Without this nothing will really work with Identity or other EF stuff.

Also, asp-validation-summary used to take full enumeration like ValidationSummary.All but now it only takes All so better fix those.

If you're using template provided ManageController etc better create a new empty project and copy those. There are some changes like User.GetUserId() is now _userManager.GetUserId(User) and FindByIdAsync() is GetUserAsync().

You can't ask User.IsSignedIn() anymore, now you need SignInManager.IsSignedIn(User) and username comes from UserManager.GetUserName(User).

After all the hassle I now have my app back in running condition. Time to actually make it do something then!

Add comment