By Camilo Jaramillo and Luis Mejia

October 14, 2019

Today, more than ever before, the excitement about .Net is being noticed among the members of one of the most vibrant communities out there. With the complete framework being open-sourced on GitHub and with many non-Microsoft people actively contributing with their Pull Requests, plus the support of organizations like the .Net foundation, there has not been a better moment to be a .Net developer and we at MAS Global are very happy to be part of this great community.

After nine previews and one release candidate, Microsoft has finally announced .Net Core 3.0 as part of the .Net Conf 2019, a virtual event that took place at the end of last month and was streamed globally, addressing the latest developments across the .Net platform, open-source, and dev tools.

You can download it here for Windows, Linux, and Mac (It is compatible with previous versions). VS 2019 16.3 or VS for Mac 8.3 are required to be updated to use it.

Although different topics were addressed during the three days of the conference, like improvements to the Visual Studio IDE, support to different open source projects from the community like Identity Server and others, the king of the event was definitely the new .Net Core release.

Let’s go first to put in context that the previous versions of .Net Core primarily supported only web and cloud application types.

Now as part of the new version, we have more capabilities to work with and much more interesting technologies such as Artificial intelligence, Internet of Things and Desktop Applications:

In this post, we would like to discuss some of the most significant improvements and capabilities that shipped with .Net Core 3.0.

Desktop Development

Perhaps the most evident effort coming is the support for Windows Forms and Windows Presentation applications that allow you to run new and existing Windows desktop apps (on Windows Operative system) under .Net core.

“The milestone’s importance comes from the addition of crucial new capabilities, such as desktop development, that weren’t available in prior versions”.

Note: Moving to .NET Core won’t make your Windows desktop application run on a Mac or Linux.

C# 8 

One of the most awaited features of .NET Core 3.0 is the latest version of C# as well as some internal improvements to the compiler.

As the Platform is evolving, so are languages like C#, and there are good amounts of new cool features shipping with the new version of C# that are supported by the new version of .Net Core. 

Default interface members: Today, once you publish an interface, it’s game over: You can not add members to it without breaking all the existing implementers of it.

Therefore, this new feature aims to support virtual methods to enable an API author to add methods to an interface in future versions without breaking source compatibility with existing implementations of that interface. Hence existing clients of the interface wouldn’t be forced to implement it.

Moreover, this feature enables C# to interoperate with APIs targeting Android (Java) and iOS (Swift), which support similar features.

interface ILogger
{
  void Log(LogLevel level, string message);
  void LogError(string message) 
  {
      Log(LogLevel.Error, message);
  };
}

Async streams: Before this new version the “Async/Await” pattern improved the responsiveness but it was limited to get only a single result.

Hence this is not helpful when we want to consume or produce continuous streams of results. For instance, data from IoT devices or cloud services.

C# 8 adds Async Streams, which allows an async method to return multiple values enriching its usability through the new IAsyncEnumerable + yield mechanism:

static async Task Main(string[] args)
{
    await foreach(var dataPoint in FetchIOTData())
    {
        Console.WriteLine(dataPoint);
    }
 
    Console.ReadLine();
}
 
static async IAsyncEnumerable FetchIOTData()
{
    for (int i = 1; i <= 10; i++)
    {
        await Task.Delay(1000);//Simulate waiting for data to come through.
        yield return i;
    }
}

– Notice that we await our foreach loop itself rather than awaiting the FetchIOTData method call within the foreach loop.

– We are returning a type of IAsyncEnumerable<T> and not IEnumerable<T>

Fast Native JSON Support

Over the years, the .Net ecosystem has heavily relied on the JSON.Net (NewtonSoft.Json) library as the primary option for manipulating JSON Formatted data. Asp.Net core was not the exception and in the previous versions, it came with JSON.Net as a dependent which did not make it possible to use Asp.Net core without that library.

Now as part of the System.Text.Json namespace, a set of new APIs for fast Json write/read operations has been exposed as a first-class citizen of .Net Core. 

The most common use cases for most people will be serialized and deserialize objects and JSON formatted data respectively. Here’s a basic example of how that can be achieved with the JsonSerializer class.

Imagine we have a simple POCO like this:

public class Car
{
     public string Brand { get; set; }
     public int Year { get; set; }
     public int Miles { get; set; }
}

Serializing and deserializing will be as simple as the following;

var car = new Car { Brand = "Ferrari", Miles = 21000, Year = 2018 };
var jsonCar = JsonSerializer.Serialize(car);
var newCar = JsonSerializer.Deserialize(jsonCar);

JsonDocument is another useful class shipping under System.Text.Json that allows us to parse JSON formatted data into a Document Object Model that can be easily queried and traversed

public static void ReadJson(string jsonString)
{
    using var document = JsonDocument.Parse(jsonString);

    var root = document.RootElement;
    var version = root.GetProperty("version").GetString();
    var configurations = root.GetProperty("configurations");

    Console.WriteLine($"Launch Version: {version}");

    foreach (var config in configurations.EnumerateArray())
    {
        var name = config.GetProperty("name").GetString();
        Console.WriteLine($"Config: {name}");
    }
}

To learn more about the new built-in JSON APIs go take a look at the documentation here.

Blazor

Blazor is a project that recently graduated from the experimental stage and is now included in this .NET Core version that lets .NET-centric developers for Web development to create interactive Web UIs using C# instead of JavaScript. Also, it allows share app logic across servers and clients written in .NET.

The result:

gRPC and Http 2

gRPC is a Remote Procedure Call Open-Source framework created by Google that’s becoming really popular especially for people building microservices, as they find it easy, yet an effective, secure and high performant way to communicate among their different applications. 

Support for gRPC has been added as part of the new release with built-in tooling and packages for creating and consuming gRPC services. 

Microsoft has been contributing directly to the gRPC open source project in GitHub and has created a new package called grpc-dotnet as an alternative of the gRPC for c# implementation that was initially provided by Google. Both implementations co-exist and there’s no plan for one to replace the other; although, if using .net framework, grpc-dotnet is not supported and you will have to go with the gRPC for C# api.

The new, Visual Studio release version 16.3 also includes new templates for creating gRPC services, as well as wizard-like connectivity from .proto file contracts to generate Server or Client-side code.

See how you can create a simple gRPC Server and Client for .Net  here.

The Future

In summary, the release has been a huge success and there’s way more involved as part of .Net 3.0 than what was discussed in this blog post. If you want to find out more about what’s new, please click here.

The excitement about .Net doesn’t end with the new version. The teams working on building this amazing platform aren’t stopping at all and are already planning ahead for what seems to be a bright future. A unified platform will be the direction moving forward as the team plans to take the capabilities of .Net Core, .Net Framework, Xamarin, and Mono and combine them into a powerful platform which might be called .Net 5.

The reason for not moving forward with a .Net Core 4 version is to not confuse people with existing 4.x versions of the .Net framework.

.Net 5 is expected to be released in November 2020, and from that point on, a yearly major version is planned to be released every November as minor releases will happen in the middle as needed.

With no more to add, just go ahead and get hands-on with .Net Core 3.0 and explore the new capabilities and improvements that the new version has to offer. 

To learn more about the whole list of features and capabilities that come with the new release please visit the official documentation.