SnowConvert
The best available tools to perform code migrations from a source database or Spark application to Snowflake.

Oracle
Spark Scala
Spark Python
SQL Server
Teradata

Data Solutions
The premier productivity workbench designed and optimized for teams using Snowflake.

Translation with SnowConvert
Edit, Debug & Deploy
Automated Test Case Generation
Metadata Analysis
Source Code Management

Get Started
There are countless ways to take advantage of BlackDiamond Studio and SnowConvert.

Migration and Other Snowflake Services
Get Up and Running with Snowpark
Using the SnowConvert Trial
Build a Cross-Platform Object Inventory

Monetize Your Data

We Are GAP Mobilize
Free Assessment Tool

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <TargetFramework>netcoreapp3.1</TargetFramework>
        <TypeScriptToolsVersion>2.5</TypeScriptToolsVersion>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <StartupObject>WebSite.Startup</StartupObject>
        <AssemblyName>SKS</AssemblyName>
        <ProjectGuid>c83435e8-3b9f-4b39-b67f-c83120cafc71</ProjectGuid>
        <Deterministic>False</Deterministic>
    </PropertyGroup>

 

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.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute("DefaultApi", "api/{controller}/{id}");
                endpoints.MapHealthChecks("/health");
            });

 

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;
                });
            services.AddHealthChecks();

 

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:VB6.NETC#WindowsWeb Application DevelopmentVBUC.NET Corewebappsvb.net

Comments

Subscribe to Mobilize.Net Blog

More...

More...
FREE CODE ASSESSMENT TOOL