ASP.NET Core Updates in .NET 5 Preview 7

Sourabh Shirhatti [MSFT]

.NET 5 Preview 7 is now available and is ready for evaluation. Here’s what’s new in this release:

  • Blazor WebAssembly apps now target .NET 5
  • Updated debugging requirements for Blazor WebAssembly
  • Blazor accessibility improvements
  • Blazor performance improvements
  • Certificate authentication performance improvements
  • Sending HTTP/2 PING frames
  • Support for additional endpoints types in the Kestrel sockets transport
  • Custom header decoding in Kestrel
  • Other minor improvements

Get started

To get started with ASP.NET Core in .NET 5 Preview 7 install the .NET 5 SDK.

You need to use Visual Studio 2019 16.7 Preview 5 or newer to use .NET 5 Preview 7. .NET 5 is also supported with the latest preview of Visual Studio for Mac. To use .NET 5 with Visual Studio Code, install the latest version of the C# extension.

Upgrade an existing project

To upgrade an existing ASP.NET Core app from .NET 5 Preview 6 to .NET 5 Preview 7:

  • Update all Microsoft.AspNetCore.* package references to 5.0.0-preview.7.*.
  • Update all Microsoft.Extensions.* package references to 5.0.0-preview.7.*.
  • Update System.Net.Http.Json package references to 5.0.0-preview.7.*.

See the full list of breaking changes in ASP.NET Core for .NET 5.

Upgrade existing Blazor WebAssembly projects

To upgrade an existing Blazor WebAssembly project, update the following properties:

From

<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>

To

<TargetFramework>net5.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<UseBlazorWebAssembly>true</UseBlazorWebAssembly>

Also, remove any package references to Microsoft.AspNetCore.Components.WebAssembly.Build, as it is no longer needed.

What’s new?

Blazor WebAssembly apps now target .NET 5

Blazor WebAssembly 3.2 apps have access only to the .NET Standard 2.1 API set. With this release, Blazor WebAssembly projects now target .NET 5 (net5.0) and have access to a much wider set of APIs. Implementing Blazor WebAssembly support for the APIs in .NET 5 is a work in progress, so some APIs may throw a PlatformNotSupportedException at runtime. We’d love to hear from you if you’re blocked by the lack of support for specific APIs.

Updated debugging requirements for Blazor WebAssembly

To enable debugging of Blazor WebAssembly apps in Visual Studio Code, you previously needed to install the JavaScript Debugger (Nightly) extension. This is no longer required as the JavaScript debugger extension is now shipped as part of VS Code. If you’ve previously installed the JavaScript Debugger (Nightly) extension you can now uninstall it. Enabling the preview version of the JavaScript debugger through the Visual Studio Code settings is still required.

Blazor accessibility improvements

The built-in Blazor input components that derive from InputBase now render aria-invalid automatically when the validation fails.

Blazor performance improvements

One of the major areas of investment for Blazor WebAssembly in .NET 5 is improving runtime performance. This is a multifaceted effort. Below are some of the high-level areas being optimized:

  • .NET runtime execution
  • JSON serialization
  • JavaScript interop
  • Blazor component rendering

Improving Blazor WebAssembly runtime performance for .NET 5 in an ongoing effort. This release contains some initial performance improvements, and we expect to share more details on the results of this performance work for future .NET 5 updates.

Certificate authentication performance improvements

We have added caching to certificate authentication in ASP.NET Core. Caching certificate validation significantly improves the performance of certificate authentication. Our benchmarks show a 400% improvement in requests per second once caching was enabled.

You don’t need to make any changes to your app to take advantage of performance improvements; caching is on by default. There are options to tune or disable caching if you wish.

Find out more about certificate authentication in ASP.NET Core in the docs.

Sending HTTP/2 PING frames

HTTP/2 has a mechanism for sending PING frames as a way of ensuring whether an idle connection is still functional. This is especially useful to have when working with long-lived streams that are often idle but only intermittently see activity (for example, gRPC streams). We have added the ability to send periodic PING frames in Kestrel by setting limits on KestrelServerOptions.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel(options =>
            {
                options.Limits.Http2.KeepAlivePingInterval = TimeSpan.FromSeconds(10);
                options.Limits.Http2.KeepAlivePingTimeout = TimeSpan.FromSeconds(1);
            });
            webBuilder.UseStartup<Startup>();
        });

Support for additional endpoints types in the Kestrel sockets transport

Building upon new API introduced in System.Net.Sockets, the sockets transport (default) in Kestrel now allows you to bind to both existing file handles and unix domain sockets. Support for binding to existing file handles enables using the existing Systemd integration without requiring you to use the libuv transport.

Custom header decoding in Kestrel

We added the ability to specify which System.Text.Encoding to use to interpret incoming headers based on the header name instead of defaulting to UTF-8. You can set the RequestHeaderEncodingSelector property on KestrelServerOptions to specify which encoding to use.

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.ConfigureKestrel(options =>
            {
                options.RequestHeaderEncodingSelector = encoding =>
                {
                    switch (encoding)
                    {
                        case "Host":
                            return System.Text.Encoding.Latin1;
                        default:
                            return System.Text.Encoding.UTF8;
                    }
                };
            });
            webBuilder.UseStartup<Startup>();
        });

Other improvements

  • CompareAttribute can now be applied to properties on Razor Page model.
  • Parameters and properties bound from the body are considered required by default.
  • We’ve started applying nullable annotations to ASP.NET Core assemblies. We intend to annotate most of the common public API surface of the framework during the .NET 5 release.
  • Authorization when using endpoint routing now receives the HttpContext rather than the endpoint instance. This allows the authorization middleware to access the RouteData and other properties of the HttpContext that were not accessible though the Endpoint class. The endpoint can be fetched from the context using context.GetEndpoint().
  • The default format for System.Diagnostics.Activity now defaults to the W3C format. This makes distributed tracing support in ASP.NET Core interoperable with more frameworks by default.
  • FromBodyAttribute now supports configuring an option that allows these parameters or properties to be considered optional:

public IActionResult Post([FromBody(EmptyBodyBehavior = EmptyBodyBehavior.Allow)] MyModel model) { ... }

Give feedback

We hope you enjoy this release of ASP.NET Core in .NET 5! We are eager to hear about your experiences with this latest .NET 5 release. Let us know what you think by filing issues on GitHub.

Thanks for trying out ASP.NET Core!

19 comments

Discussion is closed. Login to edit/delete existing comments.

  • Ben Hayat 0

    Are there any plans in .Net 5 to support building GraphQL server in ASP.Net, than using third party library?

    Secondly, is MONO being replaced by .Net 5 for Blazor WASM?

    I was looking at GQL Foundation ( https://foundation.graphql.org/members/ ) and I was surprised to see Microsoft wasn’t there. GQL is a fast growing market, and MSFT is getting behind like they did with Mobile market.

    • Rehan Saeed 0

      You can use the open source HotChocolate for this https://hotchocolate.io/.

      • Ben Hayat 0

        That’s what I’m doing for now. But I wanted to see what MSFT has to say…

        • Daniel RothMicrosoft employee 0

          Hi Ben. There are no plans currently to add GraphQL support at this time. I would look for a community-based offering.

          And yes, with this release the core libraries used by Blazor WebAssembly in this release have been switched over to the .NET 5 core libraries instead of the Mono ones. We are still using the .NET IL interpreter though.

          • Jeremy Whiteley 0

            This is very short sighted of Microsoft. Seems everyone is starting to use GraphQL. This is another example where Microsoft will be playing catch up later.

  • Stephen Brown 0

    Hi, any update on Blazor hot reloads and AOT?

    • Yasser SASSI 0

      And CSS isolation

      • Daniel RothMicrosoft employee 0

        Hi Yasser. Yup, CSS isolation is being worked on for an upcoming .NET 5 preview. Stay tuned!

    • Daniel RothMicrosoft employee 0

      Hi Stephen. Unfortunately, Blazor support for hot reload and AoT compilation both had to be pushed out to .NET 6 due to the short remaining timeframe for .NET 5. We are working on some improvements to dotnet watch for .NET 5 that should improve the dev experience from the command-line. We are also working on improving Blazor WebAssembly performance in .NET 5 as mentioned above..

  • Rogier van der Hee 0

    Are there any updated Blazor templates? If I create a new app after upgrading VS to 16.7 Preview 5 it still creates an app using 3.2.1

    • Daniel RothMicrosoft employee 0

      Hi Rogier. In addition to updating VS to the latest preview, you also need to separately install the .NET 5 SDK from the https://dot.net site. We expect to starting shipping .NET 5 with VS starting in 16.8.

      • Wil Wilder Apaza Bustamante 0

        this comment has been deleted.

      • David Bowser 0

        I have the same question. I have been building a project on Blazor since the early experimental versions. The latest version didn’t look like it would break much but it sure has for me.

        To try to understand the changes I thought I would start with the simplest case of just running the template project to see what changed but that doesn’t even build.

        I updated to the latest Visual Studio Version 16.8.0 Preview 1.0
        I downloaded and installed dotnet-sdk-3.1.401-win-x64
        I created a new project using the Blazor WebAssembly template with Core Hosting selected.
        I tried to build it and get an error ‘rzc generate exited with code 2.’
        When I look at the project file, it still specifies netstandard2.1.
        I made the changes listed above and now get 3 errors. The last is ‘The runtime pack for Microsoft.NETCore.App.Runtime.browser-wasm was not downloaded.

        I am surprised that the template project will not build and run. Am I missing something? Please help since our project is broken now.

        Thanks!

  • Steve Croxford 0

    When upgrading an existing Blazor Wasm PWA project, I ran into the following error: “error MSB4044: The “WriteLinesToFile” task was not given a value for the required parameter “File””
    Turns out this was due to a change in the registration of the service worker that wasn’t mentioned in this post, and I only found by comparing with the latest project templates. To save others the hassle, you may want to update the blog to mention this change.

  • Elver Rodriguez 0

    How to create a net core project with visual basic or will there be no compatibility? only console apps and unit tests possible

  • Mohamed moawwad 0

    Really great article, thanks for sharing.
    Cleaning

  • Rov 0

    Yeah love this update Blazor WebAssembly in .NET 5 is improving runtime performance. Many Thanks.

    download game pc .

  • Ivan Montilla Paniagua 0

    After updating from .NET Core 3.1 directly to Preview 7, I got error NETSDK1073 when building:

    NETSDK1073: The FrameworkReference ‘Microsoft.AspNetCore.App’

    • Ivan Montilla Paniagua 0

      Solved. My Blazor project was referencing other project that use Web sdk intead of Razor sdk. More info: https://github.com/dotnet/aspnetcore/issues/24889

Feedback usabilla icon