Click me
Kickstart your modernization with Digital Transformation Starter Kit - Free Download
Announcing Mobilize.Net and Snowflake partner to migrate data warehouses to the cloud.

How to Upgrade ASP.NET Core 2.2 to .NET Core 3.1 LTS

by Mauricio Rojas, on Dec 12, 2019 7:17:45 AM

Scott Hanselman is one of my geek heroes. So when I saw his excellent post  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 are going to upgrade it to the 3.1.

Step 1 - Upgrade to .NET Core 3.1 LTS

Ok. So the first thing is to edit the csproj file:

<Project Sdk="Microsoft.NET.Sdk.Web">


Step 2 - Change Startup Configuration

Next, you need to update public void Configure(IApplicationBuilder app, IHostingEnvironment env) to public void Configure(IApplicationBuilder app,IWebHostEnvironment env). IHostingEnviroment was deprecated.

I think the biggest change when upgrading AP.NET Core to 3.1 is related to setting up your routes with the AddMVC.

For example, Iin ASPNet Core 2.2 you could write:

 app.UseMvc(routes =>
                routes.MapRoute("DefaultApi", "api/{controller}/{id}");


But on .NET Core 3.1 you have to adjust that code to something like this:

            app.UseEndpoints(endpoints =>
                endpoints.MapControllerRoute("DefaultApi", "api/{controller}/{id}");


All of the configuration steps are detailed in the microsoft docs for upgrading to .NET Core 3.0

Step 3 - Add Health Check Support

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.

Step 4 - Test Your Update

At this point everything is 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 a change related to this ASP .NET Core Issue

But that is easy to fix.

You just add at the end of the ConfigureServices these lines:

            // If using IIS:
            services.Configure<IISServerOptions>(options =>
                options.AllowSynchronousIO = true;
            // If using Kestrel:
            services.Configure<KestrelServerOptions>(options =>
                    options.AllowSynchronousIO = true;


And... you are done!.

Last Step. Run the upgraded app on .NET Core 3.1

You can check out the code on our github repo.


As you can see, once you modernize a legacy app, either VB6, WinForms, PowerBuilder or Delphi you get a more open flexible platform.

The Hanselman blog post I mentioned earlier goes deep into other interesting stuff like publishing to azure and using side loading.

Check his post. He is really wise guy. 


Topics:Visual Basic Upgrade CompanionVB6convert Windows to Web.NETC#Web Application Development.NET CorewebappsNETCORE3.1


Mobilize.Net Blog

Mobilize.Net accelerates and simplifies the transformation of software applications to .NET, web, mobile, and cloud platforms.
More →


Subscribe to Updates