By continuing to use our website, you consent to the use of cookies. Please refer our cookie policy for more details.
    Grazitti Interactive Logo

      Microsoft .NET

      Everything You Need to Know About .NET 8

      Jun 29, 2023

      8 minute read

      As per Statista, 34.55%[i] of developers are using the .NET framework and libraries, globally.

      This free, cross-platform, and open-source programming framework has been around for over two decades enabling the development of various web, mobile, and cloud computing applications. Not just this, .NET is powering some of the most impressive business applications including Stack Overflow, Accenture, Deloitte, T-Mobile, and Schneider Electric.

      Since its inception, .NET framework has announced 7 releases, each with a new set of enhancements. Recently, .NET announced its next major release, .NET 8, which is expected to be available in November 2023.

      The .NET 8 is a successor to .NET 7 and comparatively offers enhanced performance, improved diagnostic and observability, expanded cross-platform support, advanced tooling & integration, long-term support (LTS), and a lot more.

      In fact, a comparison benchmark test between .NET 8 and .NET 7 concluded a performance improvement of about 2.3%[ii] in favor of .NET 8. This progress can be attributed to several new features in Dot NET, such as improvements in the JIT compiler, hardware intrinsic, and garbage collector.

      In this blog post, we’ll take a closer look at the latest additions in the .NET 8 framework and the benefits you can reap by using it in your app development.

      Upgrades and Enhancements in .NET 8

      The .NET platform has announced four previews for .NET 8. They come packed with unique features and upgrades to improve your app performance, language aspect, and more. Let’s explore them.

      Everything You Need to Know About .NET 8

      Software Development Kit (SDK) Changes

      1. Terminal Build Output: The dotnet build command builds a project and its dependencies into a set of binaries. In .NET 8, this command offers a new option to produce a more modernized build output.

      This terminal logger output enhances the grouping of errors based on their respective projects, improves the distinction between different target frameworks in multi-targeted projects, and offers real-time updates on the build process.

      2. Simplified Output Paths: In .NET 8, a new feature has been introduced to streamline the output path and folder structure for build outputs. Previously, .NET applications generated a deep and intricate set of output paths for various build artifacts.

      However, the updated approach simplifies this structure by consolidating all build outputs into a unified location. This change facilitates better predictability and compatibility with various development tools and utilities.

      3. Dotnet Workload Clean Command: The .NET 8 introduces a new command to clean up any leftover workload packs that may accumulate over multiple .NET Software Development Kit (SDK) or Visual Studio updates.

      So now onwards, if you come across challenges while managing workloads, utilize the workload clean command to safely restore to a known state before attempting further actions.

      4. Dotnet Publish and Dotnet Pack Assets: In .NET 8, the default behavior of the dotnet publish and dotnet pack commands has been updated to generate Release assets instead of Debug assets. Now, these commands could be used to build and package your code for different purposes.

      The dotnet build command prepares your code for execution and places the output in the Debug folder. Whereas, the dotnet publish command prepares your code for production use and saves the output in the Release folder.

      On top of it, you can switch back to generating development-friendly assets by using a command option that sets the configuration to Debug.

      5. Template Engine: In .NET 8, the template engine has been enhanced to provide a more secure experience by incorporating security features from NuGet. These improvements include:

      • Preventing downloading packages from insecure http:// feeds. Therefore, if a source URL does not use https, attempting to install the template package will fail.
      • For commands such as dotnet new, dotNET new install, and dotnet new update, the template engine now checks for known vulnerabilities in the template package.
      • The dotnet new command now provides information about the owner of the template package.
      • The dotnet search and dotnet uninstall commands indicate whether a template is installed from a package that is considered “trusted.” Trusted packages use a reserved prefix, providing an indication of their reliability.

      Serialization Improvements

      In .NET 8, several improvements have been made to the serialization and deserialization functionality of System.Text.Json. These include

      1. Performance and reliability enhancements for the source generator in native AOT apps.
      2. Support for serializing types with required and init properties.
      3. Customization of handling members that are not present in the JSON payload.
      4. Explicit control over frozen JsonSerializerOptions instances.
      5. Replacement of deprecated AddContext() method with TypeInfoResolver and TypeInfoResolverChain properties.
      6. Support for compiler-generated or unspeakable types in weakly typed source generation scenarios, allowing System.Text.Json to dynamically determine the appropriate supertype for serialization at runtime.

      Everything You Need to Know About .NET 8

      Core .NET Libraries

      1. Time Abstraction: The new TimeProvider class and ITimer interface in .NET 8 enable mock time in test scenarios. Also, it provides functionalities to retrieve local and UTC time, obtain timestamps for performance measurement, and create timers.

      2. UTF8 Improvements: The introduction of the IUtf8SpanFormattable interface in .NET 8 enables writing string-like representations of your data type to UTF8 destinations. It also supports formatting to UTF8 from various primitive data types and provides TryWrite methods for UTF8-based formatting. This ultimately improves the UTF8 handling.

      3. Methods for Working with Randomness: The System.Random and System.Security.Cryptography.RandomNumberGenerator data types in .NET introduce new methods for working with randomness. These include GetItems() for randomly choosing items from an input set and Shuffle() for reducing training bias in machine learning.

      4. Performance-Focused Data Types: The new System.Collections.Frozen namespace in .NET 8 introduces FrozenDictionary<TKey, TValue> and FrozenSet data types that allow read-only collections for faster read operations. Additionally, System.Buffers.IndexOfAnyValues provides optimized searching for the first occurrence of any value in a collection. These data types ultimately improve the application performance.

      5. System.Numerics and System.Runtime.Intrinsics: Vector256, Matrix3x2, and Matrix4x4 have improved the hardware acceleration on .NET 8. The hardware intrinsics in .NET 8 are annotated with the ConstExpected attribute, ensuring you get information on when the underlying hardware expects a constant or a non-constant. Additionally, the added Lerp(TSelf, TSelf, TSelf) API provides linear interpolation between the two values to be performed efficiently and accurately.

      6. Data Validation: The System.ComponentModel.DataAnnotations namespace in .NET 8 includes new attributes for data validation in cloud-native services. While the existing DataAnnotations validators primarily focus on validating user-input data, particularly for UI data-entry scenarios. The new attributes are specifically designed to validate non-user-entry data, such as configuration options.

      Extension of .NET Libraries

      1. ValidateOptionsResultBuilder Type: The ValidateOptionsResultBuilder data type simplifies the creation of ValidateOptionsResult objects, allowing for the accumulation of multiple errors during validation. This is particularly useful when implementing the IValidateOptions.Validate method, as it enables better handling of validation errors.

      2. Garbage Collection Memory Limit Adjustment: Dot NET 8 introduces the ability to dynamically adjust the memory limit for garbage collection. This is beneficial in cloud-service scenarios where resource consumption needs to scale up and down based on demand. Also, the _RefreshMemoryLimit API allows updating the garbage collector with the new memory limit, ensuring efficient resource utilization.

      3. Source Generator for Configuration Binding: ASP.NET Core uses configuration providers to read key-value pair data from various sources for app configuration. With the introduction of a source generator in .NET 8, you can opt-in to generate binding implementations for configuration mapping. This eliminates the reliance on reflection – which cause issues with trimming and Native AOT – and improves performance and compatibility.

      Reflection Improvements

      In the previous versions of .NET, when working with function pointers and using reflection operations like typeof or FieldInfo.FieldType, an IntPtr was returned instead of a System.Type object. This limited the ability to access the metadata of function pointers, such as calling conventions, return types, and parameters.

      However, in .NET 8, improvements have been made to reflection to support function pointers. Now, when using typeof or working with FieldInfo.FieldType on a function pointer, a System.Type object is returned. This enables you to access and utilize the metadata associated with function pointers, allowing for more comprehensive reflection operations on these data types.

      Native Ahead-of-Time (AOT) Support

      Native AOT publishing enables you to create a self-contained version of your app, eliminating the dependency on a runtime. In .NET 8, there are several improvements to the native AOT publishing:

      1. With .NET 8, you can publish your app with native AOT for both the x64 and Arm64 architectures on macOS.

      2. The size of native AOT apps on Linux has been reduced by up to 50% compared to .NET 7. This optimization helps to minimize the footprint of your application.

      3. You now have the ability to specify an optimization preference for your native AOT app, either for size or speed.

      Performance Improvements

      In .NET 8, several improvements have been made to code generation and just-in-time (JIT) compilation.

      1. Arm64 performance enhancements
      2. Single Instruction, Multiple Data (SIMD) improvements
      3. Support for AVX-512 (Advanced Vector Extensions) ISA extensions
      4. Cloud-native improvements
      5. Profile-Guided Optimization (PGO) improvements
      6. Just-in-Time (JIT) throughput improvements
      7. Loop and general optimizations
      8. Optimized access for fields marked with ThreadStaticAttribute
      9. Consecutive register allocation
      10. JIT/NativeAOT memory operations

      How .NET Will Improve Programming Efficiency

      1. Improved Performance: .NET 8 includes various optimizations and enhancements to the app runtime, used libraries, and languages. This ensures your applications run faster and consume less memory or resources. For example, .NET 8 introduces native Ahead-of-Time (AOT) compilation, which improves startup time and reduces code size.

      2. Enhanced Diagnostics: .NET 8 provides better tools and APIs for monitoring, profiling, and debugging applications. For example, .NET 8 supports EventPipe on Windows, Linux, and macOS, which enables low-overhead tracing of events from the runtime and libraries.

      3. Expanded Cross-Platform Support: .NET 8 continues to support a range of operating systems and architectures, including Windows, Linux, macOS, iOS, Android, and WebAssembly. Not just this, it offers added support for new platforms such as Windows 11 and Apple Silicon.

      4. Advanced Language Features: .NET 8 offers new enhancements in the C# and F# languages to provide a more streamlined and expressive coding experience. For example, C# 12 now introduces improved pattern matching, record types, and nullable reference types.

      5. Long-Term Support: .NET 8 is an LTS release with security and reliability updates for at least three years. This gives developers and businesses more confidence and stability when building and deploying .NET applications.

      A programming framework is the backbone of secure, compatible, and scalable applications. Businesses that want to build feature-rich and user-friendly applications need to consider .NET 8 framework. This new release will eliminate the shortcomings of previous .NET variants, enabling developers to deploy high-performing applications.

      Frequently Asked Questions About .Net 8

      Ques 1: What are the biggest changes in .Net 8?
      Ans: In .NET 8, significant changes include

      – The introduction of a modernized terminal build output for clearer error grouping and real-time updates
      – Streamlined output paths for simpler build artifact organization
      – The new ‘dotnet workload clean’ command for managing workloads
      – Enhancements in serialization
      – Native AOT support for improved performance
      – Expanded cross-platform support, marking substantial updates
      – Performance optimization and long-term support for greater stability and efficiency in development

      Ques 2: How does the OnChange event of Blazor InputFile behave within a repeating component in .NET 8 applications?
      Ans: In .NET 8 applications utilizing Blazor InputFile within repeating components, developers may face difficulties with the OnChange event not properly identifying its originating component. This issue highlights the need for specific mechanisms or strategies within .NET 8’s Blazor framework to accurately track and associate events with their respective component instances.

      Ques 3: How does the FromRoute attribute function in AOT-compiled .NET 8 applications?
      Ans: In AOT-compiled .NET 8 applications, the FromRoute attribute is utilized to bind route parameters directly to action method parameters. However, developers must ensure that the AOT compilation process correctly interprets and handles these route bindings, as AOT compilation can affect the dynamic aspects of reflection and routing, requiring careful attention to detail in implementation.

      Ques 4: Will .Net 8 be LTS (Long-Term Support)?
      Ans: Yes, .NET 8 is an LTS release, providing consistent updates, support, and bug fixes for an extended period. This makes it a dependable option for long-term projects, ensuring stability and reliability for developers and enterprises investing in the .NET ecosystem.

      Ques 5: Is .NET 8 cross-platform?
      Ans: Yes, .NET 8 continues the tradition of being cross-platform, supporting development on Windows, Linux, and macOS. This flexibility enables developers to build and deploy applications across different operating systems, making it easier to reach a wider audience and accommodate various deployment environments efficiently.

      Everything You Need to Know About .NET 8
      Team Grazitti is adept at delivering robust .NET solutions that take your business to the next level. To discuss your .Net project requirements, drop us a line at [email protected], and we’ll take it from there.

      References:

      [i] Statista
      [ii] Medium

      What do you think?

      0 Like

      0 Love

      0 Wow

      0 Insightful

      0 Good Stuff

      0 Curious

      0 Dislike

      0 Boring

      Didn't find what you are looking for? Contact Us!