-
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 7 Preview 7 [WIP] #7455
Comments
Order and OrderDescendingSystem.Linq now has the methods Also UsagePreviously you had to call var data = new[] { 2, 1, 3 };
var sorted = data.OrderBy(static e => e);
var sortedDesc = data.OrderByDescending(static e => e); Now you could write: var data = new[] { 2, 1, 3 };
var sorted = data.Order();
var sortedDesc = data.OrderDescending(); |
Unix File ModesPreviously .NET had no built in support for getting and setting Unix file permissions, which control which users can read, write, and execute files and directories. PInvoking manually to syscalls is not always easy because some are exposed differently on different distros - for example, on Ubuntu you may have to pinvoke to In Preview 7 we introduced a new enum: public enum UnixFileMode
{
None,
OtherExecute, OtherWrite, OtherRead,
GroupExecute, GroupWrite, GroupRead,
UserExecute, UserWrite, UserRead,
...
} and APIs There is also a new overload of Usage// Create a new directory with specific permissions
Directory.CreateDirectory("myDirectory", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute);
// Create a new file with specific permissions
FileStreamOptions options = new()
{
Access = FileAccess.Write,
Mode = FileMode.Create,
UnixCreateMode = UnixFileMode.UserRead | UnixFileMode.UserWrite,
};
using FileStream myFile = new FileStream("myFile", options);
// Get the mode of an existing file
UnixFileMode mode = File.GetUnixFileMode("myFile");
// Set the mode of an existing file
File.SetUnixFileMode("myFile", UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); ReferencesA big thank you goes out to @tmds, a long-term contributor from Red Hat, who proposed, designed, and implemented this feature. |
|
|
CodeGenCommunity PRs (Many thanks to JIT community contributors!)
Arm64
Loop OptimizationsIn preview 7, we made serveral improvements on Loop Optimizations.
General Optimizations
|
System.Security.Cryptography support on WebAssembly.NET 6 supported the SHA family of hashing algorithms when running on WebAssembly. .NET 7 enables more cryptographic algorithms by taking advantage of SubtleCrypto when possible, and falling back to a .NET implementation when SubtleCrypto can’t be used. In .NET 7 Preview 7 the following algorithms are now supported on WebAssembly:
For more information, see dotnet/runtime#40074. |
Trimming and NativeAOT Breaking ChangeAll assemblies trimmed by defaultTo better align with user expectations and produce smaller and more efficient apps, trimming now trims all assemblies in console apps by default. This change only affects apps that are published with Previous behaviorPreviously, only assemblies that were opted-in with New behaviorStarting in .NET 7, trimming trims all the assemblies in the app by default. Apps that may have previously worked with For example, an app that uses If your app did have trim warnings you may see changes in behavior or exceptions. For example, an app that uses Recommended actionThe best resolution is to resolve all the trim warnings in your application. For information about resolving the warnings in your own libraries, see Introduction to trim warnings. For other libraries, contact the author to request that they resolve the warnings, or choose a different library that already supports trimming. For example, you can switch to xref:System.Text.Json?displayProperty=fullName with source generation, which supports trimming, instead of To revert to the previous behavior, set the <TrimMode>partial</TrimMode> The default .NET 7+ value is <TrimMode>full</TrimMode> |
ClientWebSocket upgrade response details
In case of failure, the status code can help to distinguish between retriable and non-retriable errors (server doesn't support web sockets at all vs. just a tiny transient error). Headers might also contain additional information on how to handle the situation. The headers are also helpful even in case of a successful web socket connect, e.g., they can contain a token tied to a session, some info related to the subprotocol version, or the server can go down soon, etc. UsageClientWebSocket ws = new();
ws.Options.CollectHttpResponseDetails = true;
try
{
await ws.ConnectAsync(uri, default);
// success scenario
ProcessSuccess(ws.HttpResponseHeaders);
ws.HttpResponseHeaders = null; // clean up (if needed)
}
catch (WebSocketException)
{
// failure scenario
if (ws.HttpStatusCode != null)
{
ProcessFailure(ws.HttpStatusCode, ws.HttpResponseHeaders);
}
} References |
GC Regions have been enabled for most platforms as part of .NET 7, to help with backward compatibility we are now also including clrgc.dll with runtime packages which can fallback to segments. To use clrgc.dll (aka standalone GC) you can use the following configuration:
|
Detecting HTTP/2 and HTTP/3 protocol errorsWhen using UsageWhen calling HttpClient methodsusing var client = new HttpClient();
try
{
var response = await client.GetStringAsync("https://myservice");
}
catch (HttpRequestException ex) when (ex.InnerException is HttpProtocolException protocolException)
{
Console.WriteLine("HTTP2/3 protocol error code: " + protocolException.ErrorCode)
} When calling response stream methodsusing var client = new HttpClient();
using var response = await client.GetAsync("https://myservice", HttpCompletionOption.ResponseHeadersRead);
using var responseStream = await response.Content.ReadAsStreamAsync();
using var memoryStream = new MemoryStream();
try
{
await responseStream.CopyToAsync(memoryStream);
}
catch (HttpProtocolException protocolException)
{
Console.WriteLine("HTTP2/3 protocol error code: " + protocolException.ErrorCode)
} References |
.NET 7 GA is available. Closing these pre-release issues. |
@GF-Huang I believe the issue is the enclosing class, |
Why the example no |
A mistake - I've updated the example above. This specific github issue isn't really an official venue for docs and details. I would focus on the official documentation for features (that is, https://learn.microsoft.com/dotnet/standard/native-interop/pinvoke-source-generation.)
I thought we had made reference to that. In fact I thought the analyzer or fixer will switch over the project or at least warn/error if |
The only one docs about It's also there's no class partial code, and no |
What's new in .NET 7 Preview 7
This issue is for teams to highlight work for the community that will release .NET 7 Preview 7
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: #7106
Preview 2: #7107
Preview 3: #7108
Preview 4: #7378
Preview 5: #7441
Preview 6: #7454
Preview 7: #7455
RC1: #7716
The text was updated successfully, but these errors were encountered: