DEV Community

Marmik soni
Marmik soni

Posted on

Transitioning from .NET to .NET Core: My Personal Journey

Transitioning to .NET Core

If you’ve been working with the classic .NET Framework for a while, the idea of moving to .NET Core (or now just .NET starting with version 5) might feel a bit intimidating. I’ve been there, and let me tell you, it can be a game-changer for performance, cross-platform support, and just modernizing your development process. But, like any big transition, there are a few bumps along the way. Here are some key lessons I learned while making the switch.

Why Bother with .NET Core?

At first, I was a bit skeptical about the switch. I mean, why fix something if it isn't broken? But once I started digging in, the benefits became pretty clear:

  • Cross-platform flexibility: You’re no longer chained to Windows. .NET Core runs on Windows, Linux, and macOS. This is especially helpful if your team is using different environments.
  • Better performance: You’ll probably notice your apps run faster with .NET Core, thanks to the optimized runtime.
  • Modern and open-source: The open-source nature of .NET Core allows for faster updates and community-driven improvements.
  • Support for microservices: If you’re moving towards microservices or containers, .NET Core is built with this in mind.

Lesson 1: Compatibility Can Be Tricky

One of the first issues I ran into was compatibility. Not all libraries and APIs in .NET Framework are available in .NET Core. Some of the older stuff like System.Drawing or WebForms, which are common in legacy apps, didn’t make the cut.

What I Did:

  • .NET Standard: I found .NET Standard to be a great compatibility bridge when working across .NET Framework and .NET Core. It makes life easier when you need to share libraries.
  • Research: For libraries that didn’t carry over, I spent some time finding alternatives. For instance, when System.Drawing wasn’t an option, I switched to using SkiaSharp, a modern cross-platform graphics library.

Lesson 2: Performance Tweaks

While .NET Core is optimized for performance, I quickly realized that some of my older practices weren’t cutting it anymore. .NET Core's architecture nudges you to adopt more efficient practices.

What Worked:

  • Asynchronous programming: If you're not already using async/await for your I/O operations, you’re missing out. .NET Core handles async I/O much better than the older framework.
  • Span: This is a game-changer for working with large chunks of data more efficiently, helping you reduce memory usage. I didn’t realize how helpful this was until I saw the impact on performance!

Lesson 3: Embrace Dependency Injection

If you’re coming from the traditional .NET Framework, you probably used third-party tools like Autofac or Ninject for dependency injection (DI). In .NET Core, DI is built into the framework. Honestly, it’s a lot more seamless once you get the hang of it.

My Approach:

  • Switching to built-in DI: I refactored my project to use .NET Core’s built-in DI instead of relying on external libraries. It was a bit of work upfront, but it made things a lot simpler in the long run.

Lesson 4: Configuration Changes

Goodbye, Web.config. In .NET Core, configuration is handled through appsettings.json (and environment variables if you're deploying in different environments). I had to adapt, but it didn’t take long to appreciate the flexibility this offers.

What I Did:

  • Move to appsettings.json: I moved all of my configuration from Web.config to appsettings.json. It’s easier to work with, and you can maintain different configurations for development, production, and testing.
  • Environment variables: This turned out to be super useful for cloud deployments. I use environment variables to easily override configuration settings depending on the environment.

Lesson 5: CI/CD and Testing

One of the cool things about .NET Core is how easy it is to integrate into your continuous integration (CI) and deployment pipelines. Plus, if you’re used to running unit tests, you’ll be happy to know that MSTest and NUnit are fully supported in .NET Core.

My Tips:

  • Upgrade your test frameworks: Make sure you’re using the latest versions of MSTest or NUnit that support .NET Core.
  • Containerization: If you haven’t containerized your apps yet, give Docker a try. It made my deployments so much smoother and consistent across environments.

Lesson 6: Dealing with Legacy Apps

If you’re working on a legacy app tied to Windows-specific technologies like WCF or Windows Forms, it can be tough. Not everything will port over cleanly to .NET Core.

What Helped:

  • Hybrid approach: Instead of doing a full rewrite, I took a hybrid approach. I moved some components (like services or APIs) to .NET Core while leaving the rest in .NET Framework. This allowed me to gradually modernize without breaking everything at once.
  • WCF Alternatives: Since WCF isn’t supported, I switched over to using gRPC for service-to-service communication. It’s fast and well-supported in .NET Core.

Final Thoughts

Moving from .NET Framework to .NET Core might feel overwhelming at first, but once you get going, it’s a smooth ride. The cross-platform support, better performance, and modern features are absolutely worth it. Whether you’re starting a new project or modernizing a legacy app, take it one step at a time and enjoy the journey!

Let me know in the comments if you’ve gone through this transition or are planning to—what challenges did you face, and what solutions worked for you?

Happy coding!


Top comments (0)