What to expect in .NET Core 3.0

Nishān Wickramarathna
9 min readApr 13, 2019

--

Visual Studio 2019 is here!(We’ve been waiting since 2017, so to speak). With that you can now use .NET Core 3.0 Preview, as it has been with the Visual Studio 2019 Preview, to use .NET Core 3.0 with Visual Studio, you’ll need Visual Studio 2019. Microsoft’s goal to create one platform to build variety of applications is admirable, whether that’s desktop or web, they’ve added cloud, mobile, gaming, IoT and AI.

You can download .NET Core 3.0 preview 3 from here.(release notes) It adds the ability to build WinForms, WTF applications on .NET Core. It gives the desktop developer flexible deployment and side by side support. For web, they have a whole bunch of new technologies around. billing client applications using razor components, using gRPC, and much more. And it has performance improvements with new C# features for productivity and less errors. With that, they have made 3 UI frameworks Open Source. Windows Forms, Windows Presentation Foundation (WPF) and Windows UI XAML library.

Notable Changes in 3.0.0 Preview 3

  • ASP.NET Core 3.0 Preview 3 (bugs, features)
  • Entity Framework Core 3.0 Preview 3
  • .NET Core SDK installers will now Upgrade in Place
  • Container image availability in the Microsoft Container Registry (MCR)
  • Docker and cgroup memory Limits
  • Index and Range
  • F# 4.6
  • dotnet fsi preview
  • .NET Standard 2.1
  • Work continues on WinForms and WPF

In .NET Core 1 and 2 only web and cloud applications were supported.

With .NET Core 3.0, we can expect full support for desktop applications, IoT applications with Raspberry Pi and Machine Learning. It focuses mainly on 3 aspects.

  1. Desktop Workloads and UI Interop.(WinForms, WPF, EF 6)
  2. Artificial Intelligence and Machine Learning.(ML.NET)
  3. Web App Development Productivity.

Desktop Improvements

XAML Islands — You can take all the WinForms controls and WPF(touch enabled) can host Universal Windows Platform(UWP), Imagine if you want to sign with your finger in an expense report application, now you will be able to do that.

XAML Controls — WinForms and WPF browser and media UWP controls can be used directly in your applications.

High DPI fixes for WinForms — As monitors get bigger with 4k and 8k you want to add a better support for high DPI.

With that it has access to all Windows 10 APIs, so new features on Windows OS can be utilized in your app and also available in .NET Framework 4.8

Why do you want to move your desktop application to .NET Core? Turns out there are multiple reasons. They have observed typically about a 30% improvement when you move an app to .NET core.

  • Development Flexibility (side by side support, machine wide or local frameworks, self contained EXEs)
  • Core runtime and API improvements
  • Performance

C# 8.0

C# 8.0 brings bunch of cool features, here I will show you few of those.

  • Range — Take a look at this GetCustomersAsync method call. Instead of passing the entire array, you can say put a subset of that array.
  • Nullable reference types — We all have applications that we get null exceptions because we didn’t have the right null checks. With C# 8.0 you can set reference types nullable. It will actually force you to put the question mark next to Customer there because it could be null.
  • Async streams — Previously async methods only could return a single type. Now async can return a collection (IEnumerable), so now you can return more than one value from a async method.
  • Switch expressions — The new switch expression is quite simple. Anyone familiar with the switch statement can say what the following code is doing:
What immediately captures attention is absence of the case and break (or return) keywords. That’s true, they are not necessary for switch expressions. What is less obvious is that what goes after the arrow (=>) is an expression. Like the right part of the assignment.
  • Recursive patterns — Recursive Patterns matching is a very powerful feature, which allows code to be written more elegantly, mainly when used together with recursion.

.NET Standard 2.1

In total, about 3k APIs are planned to be added in .NET Standard 2.1. A good chunk of them are brand-new APIs while others are existing APIs that they added to the standard in order to converge the .NET implementations even further. Here are the highlights:

  • Span<T>. In .NET Core 2.1 we will get Span<T> which is an array-like type that allows representing managed and unmanaged memory in a uniform way and supports slicing without copying. It’s at the heart of most performance-related improvements in .NET Core 2.1. Since it allows managing buffers in a more efficient way, it can help in reducing allocations and copying. Us as programmers consider Span<T> to be a very fundamental type as it requires runtime and compiler support in order to be fully leveraged. If you want to learn more about this type, make sure to read Stephen Toub’s excellent article on Span<T>.
  • Foundational-APIs working with spans. While Span<T> is available as a .NET Standard compatible NuGet package (System.Memory) already, adding this package cannot extend the members of .NET Standard types that deal with spans. For example, .NET Core 2.1 added many APIs that allow working with spans, such as Stream.Read(Span<Byte>). Part of the value proposition to add span to .NET Standard is to add theses companion APIs as well.
  • Reflection emit. To boost productivity, the .NET ecosystem has always made heavy use of dynamic features such as reflection and reflection emit. Emit is often used as a tool to optimize performance as well as a way to generate types on the fly for proxying interfaces. As a result, many of you asked for reflection emit to be included in the .NET Standard. Previously, they’ve tried to provide this via a NuGet package but they discovered that they cannot model such a core technology using a package. With .NET Standard 2.1, you’ll have access to Lightweight Code Generation (LCG) as well as Reflection Emit. Of course, you might run on a runtime that doesn’t support running IL via interpretation or compiling it with a JIT, so they also exposed two new capability APIs that allow you to check for the ability to generate code at all (RuntimeFeature.IsDynamicCodeSupported) as well as whether the generated code is interpreted or compiled (RuntimeFeature.IsDynamicCodeCompiled). This will make it much easier to write libraries that can exploit these capabilities in a portable fashion.
  • SIMD. .NET Framework and .NET Core had support for SIMD for a while now. They’ve leveraged them to speed up basic operations in the BCL, such as string comparisons.
  • ValueTask and ValueTask<T>. In .NET Core 2.1, the biggest feature was improvements in our fundamentals to support high-performance scenarios, which also included making async/await more efficient. ValueTask<T> already exists and allows to return results if the operation completed synchronously without having to allocate a new Task<T>. With .NET Core 2.1 they’ve improved this further which made it useful to have a corresponding non-generic ValueTask that allows reducing allocations even for cases where the operation has to be completed asynchronously, a feature that types like Socket and NetworkStream now utilize. Exposing these APIs in .NET Standard 2.1 enables library authors to benefit from these improvements both, as a consumer, as well as a producer.
  • DbProviderFactories. In .NET Standard 2.0 we had almost all of the primitives in ADO.NET to allow O/R mappers and database implementers to communicate. Unfortunately, DbProviderFactories didn’t make the cut for 2.0 so they’ve added it now. In a nutshell, DbProviderFactories allows libraries and applications to utilize a specific ADO.NET provider without knowing any of its specific types at compile time, by selecting among registered DbProviderFactory instances based on a name, which can be read from, for example, configuration settings.
  • General Goodness. Since .NET Core was open sourced, they’ve added many small features across the base class libraries such as System.HashCode for combining hash codes or new overloads on System.String. There are about 800 new members in .NET Core and virtually all of them got added in .NET Standard 2.1.

New in Web (ASP.NET Core 3.0)

gRPC —We have ASP. NET Web API for building RESTful APIs using JSON. But a lot of us enjoy having contracts, which tightly defines the types that can be passed via an API. And because these contracts can also be binary, you get high performance. So this is giving you high performance RPC, contract based API’s in .NET Core. The cool thing about gRPC is because it’s a standard implementation it works across a variety of languages, so it’s supported on Java, Node and many other platforms. This means if you build a gRPC endpoint in you’re .NET Core application, you can call it from a variety of languages. At the same time, you can actually call a gRPC endpoint from .NET If it’s written in Java or something else as well. So it gives you full interoperability between all these platforms.

Worker Service — ASP.NET always been kind of associated with UI, whether it is web forums, or NBC or razor pages. We’ve had Web API, but we really haven’t had a great starting point for building microservices style applications. And so they are adding a worker service template. This template is for building something that might run for a long time in the background or might listen for a message coming in from something like Azure service bus, It is a great template for building these types of applications that still give you all the great features of .NET Core, dependency injection, logging, and the high performance web server on the back end.

Web API’s + Identity — The next thing is, as you build those API’s, one of the hardest parts is securing these things. And so they’re going to make it very easy to partner with the open source identity server project and use that technology to secure your API’s.

ASP.NET Core 3.0 Razor Components (Blazor).

Razor Components decouples component rendering logic from how UI updates are applied. ASP.NET Core Razor Components in .NET Core 3.0 adds support for hosting Razor Components on the server in an ASP.NET Core app. UI updates are handled over a SignalR connection.

This lets you build client UI, in C#, you no longer have to actually depend on a library like Angular, React or Vue. You can instead, take advantage of all the capabilities of C#, for example, you can have a C# object on the server, and you can pass it to the client. And you get that strong type all the way across both of these things.

We can run this on the server side and have a JavaScript library on the client that actually does the interrupt, or even better. We have something called web assembly. And this is a mechanism where you can compile .net into pretty much native IL(Intermediate Language). So when it runs in the browser, it runs in full native speed in the browser, and requires no plugins. All the browsers support this, the mobile browsers and the desktop browsers. And even better, this web assembly runs in the sandbox of the browser. So this is not like Active X of flash or any other plugin technologies. It’s safe, stays within the context the browser and gives you that native performance. It is going to give you the ability to build awesome SPA applications just using C#.

So you’ve seen a lot of the exciting new things in .NET Core 3.0, .NET Core 3.0 will not ship as part of Visual Studio 2019. It’ll ship later this year at the Microsoft Build conference in May, will actually announced the RTM date. But because you’re running Visual Studio 2019 you can try the preview today without hurting any of your existing applications. https://dotnet.microsoft.com/download/dotnet-core/3.0

--

--

No responses yet