Scott Hanselman is one of my geek heros. So when I so his excellent post https://www.hanselman.com/blog/UpdatingAnASPNETCore22WebSiteToNETCore31LTS.aspx I said to myself "it is useless to resist"!!
So I took our legendary Salmon King Seafood App. Yep, our VB6 reference app that we had already taken to ASP.NET Core 2.2. And now with the guide of the Hanselman take it to the 3.1.
Ok. So the first thing is to edit the csproj file:
Next, you need to change public void Configure(IApplicationBuilder app, IHostingEnvironment env) to public void Configure(IApplicationBuilder app,IWebHostEnvironment env). IHostingEnviroment was deprecated.
I think the biggest change is related to setting up your routes with the AddMVC. In ASPNet Core 2.2 you could write:
But on .NET Core 3.1 you have to adjust that code to something like this:
All these is detailed at the microsoft docs for upgrading to .NET Core 3.0
The MapHealthCheck is not mandatory. I just think is a good practice to add Health Check Support
Next a minor change: add the using Microsoft.Extensions.Hosting; this is necessary to allow the IsDevelopment extension method to work.
And that point everything compiled so I gave it a try, but I got a nasty exception:
System.InvalidOperationException: Synchronous operations are disallowed. Call ReadAsync or set AllowSynchronousIO to true instead.
Oh wow!! It seems this is change related to this AspNet Core Issue https://github.com/aspnet/AspNetCore/issues/7644
But that is easy to fix. You just add at the end of the ConfigureServices these lines:
And... you are done!.
Now you can just run the app on .NET Core 3.1
You can check out the code on our github repo: https://github.com/MobilizeNet/SKSWebMap/
As you can see, once you modernized a legacy app, either VB6, WinForms, PowerBuilder or Delphi you get a more open flexible platform.
The Hanselman goes deep into other interesting stuff like publising to azure and using side loading. Check his post. He is really wise guy.