Businesses require a scalable and robust architecture to migrate and modernize their applications to microservices architecture. Cloud is the obvious choice for many as it facilitates containers, serverless platform, and offers facilities like pay-per-usage. The choice of language is .NET Core as it offers cross-platform support, flexibility, and PaaS support. With 4.8 being the last version of the .NET Framework, Microsoft has advised moving all applications to .NET Core.

This blog highlights the findings, pros, cons, suggestions, recommendations, and best practices from the experience of moving 20+ applications into .Net Core and Cloud.

Limitations in .NET Framework

The key limitation of .NET Framework is that it is tied to Windows and offers limited support for object-relation (OR). It is costly to purchase Windows licenses for a small application that you must renew year after year. This is known as vendor-locking which Microsoft has now changed for its sustenance. Third-party components and integration are complex, and each new release requires reconfiguration or bug-fixing.

When compared to other programming languages and hardware requirements, .NET Framework is always a secondary choice for customers. The performance of applications developed in the .NET Framework in early 2000 was poor due to various factors. This cannot be left unnoticed for applications that handle critical and larger businesses.

Migrate applications to .NET Core when you need performance, cross-platform, simpler package management, cost-effective deployments, scalability, open-source code base, and while adopting PaaS.

Choosing Manual Vs Automatic Migrations

Most applications can be migrated using automation tools; however, some applications cannot be migrated due to their large size and legacy enterprise status. Moreover, not all technologies are supported in .NET Core, so you will most likely encounter issues with them during migration. We discovered through experience that applications built on technologies like Application domains, .NET remoting, LINQ2SQL, Code access security (CAS), Windows Workflow Foundation (WF), etc., must be migrated manually as they are not supported in .NET Core.

It is always recommended to use automation tools for migration. Use the automation tool for the frameworks that support it, or else use the manual migration method. Please read the following article to understand more: https://learn.microsoft.com/en-us/dotnet/core/porting/

Automatic Migration

Manual Migration

  • Analyze Project Dependencies
  • Migrate from ASP.NET MVC
  • Migrate from WebForms
  • Move Your Project File
  • Test Run your Application on .NET Core

Best Practices

1. Analyze Project Dependencies (.Net Portability Analyzer)

  • Microsoft has made available the.NET Portability Analyzer, a tool for analyzing your project references and application dependencies. This tool also assists you in determining which APIs are not available in .NET Core.
  • The tool can be found as a NuGet package and as a Visual Studio extension. 
  • If you discover NuGet dependencies that are incompatible with .NET Core, there are a few options for moving forward with the migration: 
    • Contact developers for support and be mindful of their efforts and time as .NET Core is open-source and developers are volunteers.
    • Visit nuget.org and search for a package that fulfills similar functionality as the one you are using now.
    • If possible, try to write a code that will accomplish the same tasks as the package itself.

2. Migration of ASP.NET MVC applications

  • Create an empty ASP.NET core or use a Asp.NET Core Web app to start from scratch.
  • Make sure that your Global.asax.cs code is up to date. All the custom logic should move to startup class in .NET 5.
  • Move all the existing controllers and models, entities if any to the new project structure.
  • You need to update the controller classes with the new namespaces, i.e., Microsoft.AspNetCore.Mvc.ControllerBase and also update the class attributes accordingly.
  • Fix the compilation errors which occurred due to the change in the namespaces.
  • Try to use .NET middlewares in the startup class for exception handling, authentication, etc.
  • Starting from .NET Core 1.1 to .NET 5 and above we need to use appsettings.json instead of web.config.
  • Remove unnecessary files like app.config, global.asax and packages.config.

3. Migrate from WebForms

One significant disadvantage of .NET Core is that WebForms are not supported. Moving WebForms from .NET Framework to .NET Core is thus referred to as porting rather than migration.

  • This process is quite complex. Rather than attempting to port legacy code, you can rewrite your application from scratch. This can lead to a more secure and reliable application. However, this move will take a significant amount of time and effort.
  • Alternatively, you can gradually migrate the system page by page to .NET Core.

4. Move your project file

  • You can migrate your old project to the Core project using the ‘.NET migrate; command, which migrates the project.json and any other files that are required by the web application.
  • The .NET migrate command will not change your code in any way. It will simply convert your project file to use the new SDK-style project format (i.e., csproj).

5. Test Run your Application on .NET Core

  • Once your application has been migrated, it should run on any operating system that is supported. 
  • The final step in migrating your application should be to test run your existing application on .NET Core. Run your application in .NET, and if it works, you are done!

Tips For Smoother .NET To .NET Core Migration

Any framework migration will necessitate advance planning, constant monitoring, code safety, network readiness, and contingency plans to address any issues that arise.

For smoother migration,

  • Rather than migrating an entire codebase to .NET Core, you can try smaller modules/projects.
  • .NET try-convert tool helps you convert your project to the .NET Core but it is not a guaranteed solution, and it may cause subtle changes in behavior. It can be used as a starting point for automating basic tasks.
  • Identify the “base” of the library. It could be data models, classes, or methods that are critical. Create a new .NET Core project by copying the base. Make any necessary changes to compile the code. Repeat with another layer of code.

Drawbacks of .NET Core

  • .Net Core does not support Windows Forms or WPF applications.
  • .Net Core does not support WCF.
  • .Net Core does not include ASP.NET Web Pages and ASP.NET WebForms.
  • Limited support for VB .NET and F#.
  • There are currently no plans to add WF/WCF+WF/WCF Data Services to.NET Core.
  • .NET Core lacks third-party library support and some features.
  • You must have access to Windows-specific APIs. NET Core will not work if your application requires access to the Windows Registry, WMI, or other Windows-specific APIs.

Migrating from 4.5 to 4.8

  • The simplest way to upgrade the .Net Framework version is to use the Visual Studio extension Target Framework Migrator 
  • This tool will help you to migrate at one go.
  • Checkout the below link to understand what runtime changes are required while migrating from 4.5 to 4.8
https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/runtime/4.5-4.8

Takeaway

We have derived facts from a few use cases and scenarios, which are presented in the blog. At Evoke, we have larger projects with complex use cases. The thoughts, best practices, and tips presented in this write-up will help bring a different perspective while planning for your migration.

Schedule a meeting with our experts to discuss more complex scenarios.

References

Mohammad Jalil Mudabbir

Jalil is an Associate Architect at Evoke Technologies and is proficient in .Net Technologies. He likes to explore beyond his capabilities which inspired him to study about cloud resilience and eventually published it as a blog. His hobbies are studying about social and economical issues and trying to seek different approaches to solve them. He also likes meditation, swimming, and watching movies.