-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What's new in .NET 6 Preview 4 #6098
Comments
.NET Libraries: Extensions Enhancements (WIP)Hosting
In previous versions, when a BackgroundService threw an exception, the exception was lost and the service appeared to hang. .NET 6 has fixed this by logging the exception and stopping the Host when an unhandled exception is thrown. This behavior is consistent with the way other app models behave when unhandled exceptions are encountered. If you prefer to keep the previous behavior of allowing an unhandled exception in a BackgroundService to not stop the Host, you can set Options
Configuration
Logging
CachingTell the story of the feature and anything the community should pay particular attention |
Single-file Publishing ImprovementsStatic Analysis Analyzers for single-file publishing were added in .NET 5 to warn about For .NET 6 Preview 4 we've improved the analysis to allow for custom warnings. If you have an API which doesn't work in single-file publishing you can now mark it with the The analyzer is automatically enabled for exe projects when Compression Single-file bundles now support optional compression, which can be enabled by setting the property However, compression can also significantly increase the startup time of the application, especially on Unix platforms (because they have a no-copy fast start path that can't be used with compression). You should test your app after enabling compression to see if the additional startup is acceptable. |
System.Text.Json: IAsyncEnumerable Serialization Support dotnet/runtime#1570System.Text.Json now supports serializing using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
static async IAsyncEnumerable<int> PrintNumbers(int n)
{
for (int i = 0; i < n; i++) yield return i;
}
Stream stream = Console.OpenStandardOutput();
var data = new { Data = PrintNumbers(3) };
await JsonSerializer.SerializeAsync(stream, data); // prints {"Data":[0,1,2]} Note that IAsyncEnumerable values are only supported using the asynchronous serialization methods. Attempting to serialize using the sync methods will result in a Deserialization SupportDeserializing using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
var stream = new MemoryStream(Encoding.UTF8.GetBytes(@"{""Data"":[0,1,2,3,4]}"));
var result = await JsonSerializer.DeserializeAsync<MyPoco>(stream);
await foreach (int item in result.Data)
{
Console.WriteLine(item);
}
public class MyPoco
{
public IAsyncEnumerable<int> Data { get; set; }
} However it must be pointed out that the deserializer will have buffered all IAsyncEnumerable contents in memory before returning the deserialized POCO. This is because the deserializer needs to have consumed the entire JSON value before returning a result. The
|
.NET Libraries: new LINQ APIs dotnet/runtime#47231This preview includes a number of new LINQ APIs that have been requested and contributed by the community. Adding Enumerable support for
|
IL TrimmingWarnings enabled by defaultYou could previously access trim warnings, which tell you about places where trimming may remove code that's used at runtime, by setting Default TrimMode=linkIn .NET 5, trimming tried to find and remove unreferenced assemblies by default. This is safer, but provides limited benefit. Now that trim warnings are on by default developers can be confident in the results of trimming. The new default Trim Mode in .NET 6 is The First, if we publish without trimming at all: 80 MB If we publish with the legacy However, if we use the We hope that the new trim mode aligns much better with the expectations for trimming: significant savings and predictable results. Native AOTAs part of our Native AOT experiment we've implemented the same trimming warnings for AOT as well, which should improve the Native AOT compilation experience in much the same way. |
PublishReadyToRun now uses crossgen2 by defaultAs we continue the journey of enabling crossgen2 to replace crossgen, we have now enabled crossgen2 to be used by default when publishing ReadyToRun images in preview4. It also supports generating composite images which needs to be enabled explicitly however. Here are some of the setting which can be toggled:
|
.NET Libraries: Developers using FileStream find it to be high performance and robustAs noticed by @benaadams and other Community members in dotnet/runtime#40359, We have recognized that and decided to rewrite The first step we took, was implementing the Strategy Pattern which allows .NET to choose
{
"configProperties": {
"System.IO.UseNet5CompatFileStream": true
}
}
Based on the solid new fundamentals, we have ensured (dotnet/runtime#48813) that
The next step we took was optimizing the sys-calls usage (dotnet/runtime#49975):
And last but not least, greatly reduced the managed allocations:
Enough of the talking. Let's measure the improvements using BenchmarkDotNet: public class FileStreamPerf
{
private int fileSize = 1_000_000; // 1 MB
private Memory<byte> _buffer = new byte[8_000]; // 8 kB
private string _filePath = "test.file";
private FileStream _fileStream;
[GlobalSetup(Target = nameof(ReadAsync))]
public void SetupRead()
{
File.WriteAllBytes(_filePath, new byte[fileSize]);
_fileStream = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 1, useAsync: true);
}
[Benchmark]
public async ValueTask ReadAsync()
{
_fileStream.Position = 0; // read from the begining
while (await _fileStream.ReadAsync(_buffer) > 0)
{
}
}
[GlobalSetup(Target = nameof(WriteAsync))]
public void SetupWrite()
{
_fileStream = new FileStream(_filePath, FileMode.CreateNew, FileAccess.Write, FileShare.Read, bufferSize: 1, useAsync: true);
}
[Benchmark]
public async ValueTask WriteAsync()
{
_fileStream.SetLength(0); // truncate the file
for (int i = 0; i < fileSize / _buffer.Length; i++)
{
await _fileStream.WriteAsync(_buffer);
}
}
[GlobalCleanup]
public void Cleanup()
{
_fileStream.Dispose();
File.Delete(_filePath);
}
} BenchmarkDotNet=v0.12.1.1533-nightly, OS=Windows 10.0.18363.1500 (1909/November2019Update/19H2)
Intel Xeon CPU E5-1650 v4 3.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.100-preview.4.21219.1
[Host] : .NET 5.0.5 (5.0.521.16609), X64 RyuJIT
Job-JAYWNT : .NET 5.0.5 (5.0.521.16609), X64 RyuJIT
Job-ZRAEXA : .NET 6.0.0 (6.0.21.21801), X64 RyuJIT
In this particular example (Windows 10 with SSD drive with BitLocker enabled) reading 1 MB file is now 2.5 times faster, while writing is 5.5 times faster. |
.NET Libraries: Enhanced Date, Time and Time Zone support (dotnet/runtime#45318)(Blog post pending Preview 4 release) New
|
System.Text.Json: Writable DOM FeatureFor additional background see https://github.com/dotnet/designs/blob/main/accepted/2020/serializer/WriteableDomAndDynamic.md This adds a writeable DOM feature to
The basic class structure: namespace System.Text.Json.Node
{
public abstract class JsonNode {...};
public sealed class JsonObject : JsonNode, IDictionary<string, JsonNode?> {...}
public sealed class JsonArray : JsonNode, IList<JsonNode?> {...};
public abstract class JsonValue : JsonNode {...};
} and programming model: // Parse a JSON object
JsonNode jNode = JsonNode.Parse("{\"MyProperty\":42}");
int value = (int)jNode["MyProperty"];
Debug.Assert(value == 42);
// or
value = jNode["MyProperty"].GetValue<int>();
Debug.Assert(value == 42);
// Parse a JSON array
jNode = JsonNode.Parse("[10,11,12]");
value = (int)jNode[1];
Debug.Assert(value == 11);
// or
value = jNode[1].GetValue<int>();
Debug.Assert(value == 11);
// Create a new JsonObject using object initializers and array params
var jObject = new JsonObject
{
["MyChildObject"] = new JsonObject
{
["MyProperty"] = "Hello",
["MyArray"] = new JsonArray(10, 11, 12)
}
};
// Obtain the JSON from the new JsonObject
string json = jObject.ToJsonString();
Console.WriteLine(json); // {"MyChildObject":{"MyProperty":"Hello","MyArray":[10,11,12]}}
// Indexers for property names and array elements are supported and can be chained
Debug.Assert(jObject["MyChildObject"]["MyArray"][1].GetValue<int>() == 11); Noteworthy features:
|
.NET MAUIThis release has general progress on porting controls, layouts, and features from Xamarin.Forms. Progress for that is on our GitHub status report Highlights:
New in this release are: BlazorWebView
<BlazorWebView
HostPage="wwwroot/index.html"
Services="{StaticResource Services}">
<BlazorWebView.RootComponent>
<RootComponent
Selector="#app"
ComponentType="{x:Type local:Main}"
/>
</BlazorWebView.RootComponent>
</BlazorWebView> Splash ScreenAdd a static splash screen to all platforms by marking any image as a <MauiSplashScreen Include="Resources\appiconfg.svg" Color="#512BD4" /> Raw AssetsAdd other media to your single project such as documents, video, audio, etc. by settings the <MauiAsset Include="Resources\Raw\index.html" /> and then reference it by filename from any native control <WebView Source="index.html" /> New Templates |
Is there any way to understand how Remove() works for JsonNode. I guess providing a simple way to jsonNode["[MyCurrentNode["].Remove("[NodeName]") would help !! |
dotnet/sdk: Preserve destination folder option for File System publish (dotnet/sdk@a66f426)When using dotnet or msbuild to publish a project or website using the File System option, and the "Delete existing files" option is enabled, the target destination folder is deleted and recreated after deleting any existing files inside. This can have unwarranted side effects, with one such being that all file system permissions and ACL's on the target destination folder are lost. When the folder is recreated, it will be assigned permissions and ACL's based on the user account that creates it and where it is created (i.e. the recreated folder would inherit any upstream inheritable permissions, or permissions based on who created the folder in the case of a CIFS share path for example). The option to "Delete existing files" does not explicitly indicate that the target folder itself will be deleted and recreated, and this can cause issues for developers who are unaware of this behavior, particularly in situations of publishing directly to a web server or production share path where the target folder has explicit permissions applied. Now there is a new msbuild option when publishing via File System that will preserve the destination folder and yet still delete any existing files inside when the "Delete existing files" option is selected. This new option is called "PreserveDestinationFolder". Simple set this value to "true" along with "DeleteExistingFiles" to "true" when publishing, and the destination folder will not be deleted and recreated. This option is backwards compatible with existing publish profiles and publish commands that use "DeleteExistingFiles", in that if the "PreserveDestinationFolder" is not supplied or is anything else but "true", the previous behavior of deleting and recreating the target folder will still occur. Only when you supply "true" for both "DeleteExistingFiles" and "PreserveDestinationFolder" will the target folder not get deleted and recreated. By providing an opt-in option to preserve the destination folder, this issue can be bypassed, and users can still take advantage of the cleanup to remove older files that may be outdated or defunct. This option is currently not represented in the UI for Visual Studio's publish wizard, but it can be manually inserted into publish profiles by editing them or it can be passed in as parameter to dotnet or msbuild: Publish profile example
Dotnet example
Msbuild example
|
What's new in .NET 6 Preview 4
This issue is for teams to highlight work for the community that will release .NET 6 Preview 4.
To add content, use a new conversation entry. The entry should include the team name and feature title as the first line as shown in the template below.
Preview 1: #5853
Preview 2: #5889
Preview 3: #5890
Preview 4: #6098
Preview 5: #6099
The text was updated successfully, but these errors were encountered: