Skip to content

Merge main into live #46053

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

Merged
merged 7 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/ai/microsoft-extensions-ai.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,8 @@ For more samples, see the [dotnet/ai-samples](https://aka.ms/meai-samples) GitHu

## See also

- [Request a response with structured output](./quickstarts/structured-output.md)
- [Build an AI chat app with .NET](./quickstarts/build-chat-app.md)
- [.NET dependency injection](../core/extensions/dependency-injection.md)
- [Rate limit an HTTP handler in .NET](../core/extensions/http-ratelimiter.md)
- [Dependency injection in .NET](../core/extensions/dependency-injection.md)
- [Caching in .NET](../core/extensions/caching.md)
- [Rate limit an HTTP handler in .NET](../core/extensions/http-ratelimiter.md)
18 changes: 9 additions & 9 deletions docs/azure/includes/dotnet-all.md

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions docs/azure/includes/dotnet-new.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Core" Version="1.45.0" />
<PackageReference Include="Azure.Core" Version="1.46.0" />
<PackageReference Include="Azure.Security.KeyVault.Secrets" Version="4.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="Moq" Version="[4.20.72]" /> <!-- Context: https://github.com/Azure/azure-sdk-for-net/issues/38111 -->
Expand Down
8 changes: 2 additions & 6 deletions docs/csharp/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,13 @@ additionalContent:
- title: Mobile and Desktop
links:
- url: /dotnet/desktop/wpf/
text: Windows Presentation Foundation (.NET 5+)
text: Windows Presentation Foundation
- url: /dotnet/desktop/winforms/
text: Windows Forms (.NET 5+)
text: Windows Forms
- url: /dotnet/maui
text: .NET Multi-platform App UI (.NET MAUI)
- url: /azure/developer/mobile-apps
text: Develop mobile apps with Azure
- url: /dotnet/desktop/wpf/?view=netframeworkdesktop-4.8&preserve-view=true
text: Windows Presentation Foundation (.NET Framework)
- url: /dotnet/desktop/winforms/?view=netframeworkdesktop-4.8&preserve-view=true
text: Windows Forms (.NET Framework)
# Card
- title: Microservices
links:
Expand Down
23 changes: 22 additions & 1 deletion docs/csharp/misc/cs0136.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,28 @@ namespace MyNamespace
}
}
}
```
```

The compiler reports this error regardless of the textual order of the variable declarations, as shown in the following example:

```csharp
// CS0136.cs
namespace MyNamespace
{
public class MyClass
{
public static void Main()
{
if (true)
{
int i = 1; // CS0136, hides i outside this block
}
int i = 0;
i++;
}
}
}
```

From the [C# Language Specification](~/_csharpstandard/standard/basic-concepts.md#73-declarations):

Expand Down
8 changes: 4 additions & 4 deletions docs/csharp/whats-new/csharp-14.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,9 @@ Only the implementing declaration of a partial constructor can include a constru

The implementing declaration of a partial event must include `add` and `remove` accessors. The defining declaration declares a field-like event.

## Null conditional assignment
## Null-conditional assignment

The null conditional member access operators, `?.` and ``?[]`, can now be used on the left hand side of an assignment or compound assignment.
The null-conditional member access operators, `?.` and `?[]`, can now be used on the left hand side of an assignment or compound assignment.

Before C# 14, you needed to null-check a variable before assigning to a property:

Expand All @@ -157,9 +157,9 @@ customer?.Order = GetCurrentOrder();

The right side of the `=` operator is evaluated only when the left side isn't null. If `customer` is null, the code doesn't call `GetCurrentOrder`.

In addition to assignment, you can use null conditional member access operators with compound assignment operators (`+=`, `-=`, and others). However, increment and decrement, `++` and `--`, aren't allowed.
In addition to assignment, you can use null-conditional member access operators with compound assignment operators (`+=`, `-=`, and others). However, increment and decrement, `++` and `--`, aren't allowed.

You can learn more in the language reference article on the [conditional member access](../language-reference/operators/member-access-operators.md#null-conditional-operators--and-) and the feature specification for [null conditional assignment](~/_csharplang/proposals/null-conditional-assignment.md)
You can learn more in the language reference article on the [conditional member access](../language-reference/operators/member-access-operators.md#null-conditional-operators--and-) and the feature specification for [null-conditional assignment](~/_csharplang/proposals/null-conditional-assignment.md).

## See also

Expand Down
12 changes: 6 additions & 6 deletions docs/framework/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ landingContent:
links:
- text: Desktop guide introduction
url: /dotnet/desktop/
- text: .NET Framework WPF
url: /dotnet/desktop/wpf/?view=netframeworkdesktop-4.8
- text: .NET Framework Windows Forms
url: /dotnet/desktop/winforms/?view=netframeworkdesktop-4.8
- text: WPF
url: /dotnet/desktop/wpf/
- text: Windows Forms
url: /dotnet/desktop/winforms/

# Card
- title: Create WPF apps
linkLists:
- linkListType: overview
links:
- text: Overview of WPF
url: /dotnet/desktop/wpf/?view=netframeworkdesktop-4.8
url: /dotnet/desktop/wpf/
- linkListType: tutorial
links:
- text: Create your first WPF app in Visual Studio
url: /dotnet/desktop/wpf/getting-started/walkthrough-my-first-wpf-desktop-application/?view=netframeworkdesktop-4.8
url: /dotnet/desktop/wpf/getting-started/walkthrough-my-first-wpf-desktop-application/

# Card
- title: Work with data using ADO.NET
Expand Down
6 changes: 3 additions & 3 deletions docs/framework/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ items:
- name: Overview
href: install/index.md
- name: Install on Windows and Windows Server
href: install/on-windows-and-server.md
href: install/on-windows-and-server.md
- name: For developers
href: install/guide-for-developers.md
- name: Versions and dependencies
Expand Down Expand Up @@ -128,9 +128,9 @@ items:
- name: Overview
href: develop-client-apps.md
- name: Windows Presentation Foundation
href: /dotnet/desktop/wpf/?view=netframeworkdesktop-4.8&preserve-view=true
href: /dotnet/desktop/wpf/
- name: Windows Forms
href: /dotnet/desktop/winforms/?view=netframeworkdesktop-4.8&preserve-view=true
href: /dotnet/desktop/winforms/
- name: Service-oriented apps with WCF
href: wcf/
- name: Windows Workflow Foundation
Expand Down
8 changes: 2 additions & 6 deletions docs/index.yml
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,9 @@ additionalContent:
- url: /uwp
text: Universal Windows apps
- url: /dotnet/desktop/wpf/
text: Windows Presentation Foundation (.NET 5+)
- url: /dotnet/desktop/wpf/?view=netframeworkdesktop-4.8&preserve-view=true
text: Windows Presentation Foundation (.NET Framework)
text: Windows Presentation Foundation
- url: /dotnet/desktop/winforms/
text: Windows Forms (.NET 5+)
- url: /dotnet/desktop/winforms/?view=netframeworkdesktop-4.8&preserve-view=true
text: Windows Forms (.NET Framework)
text: Windows Forms
- url: /dotnet/maui
text: .NET Multi-platform App UI (.NET MAUI)
# Card
Expand Down
53 changes: 27 additions & 26 deletions docs/standard/datetime/system-text-json-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The `System.Text.Json` library parses and writes <xref:System.DateTime> and <xre

The <xref:System.Text.Json.JsonSerializer>, <xref:System.Text.Json.Utf8JsonReader>, <xref:System.Text.Json.Utf8JsonWriter>,
and <xref:System.Text.Json.JsonElement> types parse and write <xref:System.DateTime> and <xref:System.DateTimeOffset>
text representations according to the extended profile of the ISO 8601-1:2019 format. For example, `2019-07-26T16:59:57-05:00`.
text representations according to the extended profile of the ISO 8601-1:2019 format, for example, `2019-07-26T16:59:57-05:00`.

<xref:System.DateTime> and <xref:System.DateTimeOffset> data can be serialized with <xref:System.Text.Json.JsonSerializer>:

Expand All @@ -32,18 +32,16 @@ text representations according to the extended profile of the ISO 8601-1:2019 fo

:::code language="csharp" source="snippets/system-text-json-support/csharp/deserializing-with-jsonserializer-valid/Program.cs":::

With default options, input <xref:System.DateTime> and <xref:System.DateTimeOffset> text representations must conform to the extended ISO 8601-1:2019 profile.
Attempting to deserialize representations that don't conform to the profile will cause <xref:System.Text.Json.JsonSerializer> to throw a <xref:System.Text.Json.JsonException>:
With default options, input <xref:System.DateTime> and <xref:System.DateTimeOffset> text representations must conform to the extended ISO 8601-1:2019 profile. If you attempt to deserialize representations that don't conform to the profile, <xref:System.Text.Json.JsonSerializer> throws a <xref:System.Text.Json.JsonException>:

:::code language="csharp" source="snippets/system-text-json-support/csharp/deserializing-with-jsonserializer-error/Program.cs":::

The <xref:System.Text.Json.JsonDocument> provides structured access to the contents of a JSON payload, including <xref:System.DateTime>
and <xref:System.DateTimeOffset> representations. The following example shows how to calculate the average
<xref:System.Text.Json.JsonDocument> provides structured access to the contents of a JSON payload, including <xref:System.DateTime> and <xref:System.DateTimeOffset> representations. The following example shows how to calculate the average
temperature on Mondays from a collection of temperatures:

:::code language="csharp" source="snippets/system-text-json-support/csharp/computing-with-jsondocument-valid/Program.cs":::

Attempting to compute the average temperature given a payload with non-compliant <xref:System.DateTime> representations will cause <xref:System.Text.Json.JsonDocument> to throw a <xref:System.FormatException>:
If you attempt to compute the average temperature given a payload with non-compliant <xref:System.DateTime> representations, <xref:System.Text.Json.JsonDocument> throws a <xref:System.FormatException>:

:::code language="csharp" source="snippets/system-text-json-support/csharp/computing-with-jsondocument-error/Program.cs":::

Expand All @@ -55,7 +53,7 @@ The lower level <xref:System.Text.Json.Utf8JsonWriter> writes <xref:System.DateT

:::code language="csharp" source="snippets/system-text-json-support/csharp/reading-with-utf8jsonreader-valid/Program.cs":::

Attempting to read non-compliant formats with <xref:System.Text.Json.Utf8JsonReader> will cause it to throw a <xref:System.FormatException>:
If you attempt to read non-compliant formats with <xref:System.Text.Json.Utf8JsonReader>, it throws a <xref:System.FormatException>:

:::code language="csharp" source="snippets/system-text-json-support/csharp/reading-with-utf8jsonreader-error/Program.cs":::

Expand All @@ -67,8 +65,12 @@ Attempting to read non-compliant formats with <xref:System.Text.Json.Utf8JsonRea

### When using <xref:System.Text.Json.JsonSerializer>

If you want the serializer to perform custom parsing or formatting, you can implement [custom converters](xref:System.Text.Json.Serialization.JsonConverter%601).
Here are a few examples:
If you want the serializer to perform custom parsing or formatting, you can implement [custom converters](xref:System.Text.Json.Serialization.JsonConverter%601). The following sections show a few examples:

- [DateTime(Offset).Parse and DateTime(Offset).ToString](#datetimeoffsetparse-and-datetimeoffsettostring)
- [Utf8Parser and Utf8Formatter](#-and-)
- [Use DateTime(Offset).Parse as a fallback](#use-datetimeoffsetparse-as-a-fallback)
- [Use Unix epoch date format](#use-unix-epoch-date-format)

#### DateTime(Offset).Parse and DateTime(Offset).ToString

Expand Down Expand Up @@ -135,7 +137,7 @@ and then written with the <xref:System.Text.Json.Utf8JsonWriter.WriteStringValue
### When using <xref:System.Text.Json.Utf8JsonReader>

If you want to read a custom <xref:System.DateTime> or <xref:System.DateTimeOffset> text representation with <xref:System.Text.Json.Utf8JsonReader>,
you can get the value of the current JSON token as a <xref:System.String> using <xref:System.Text.Json.Utf8JsonReader.GetString> method, then parse the value using custom logic.
you can get the value of the current JSON token as a <xref:System.String> using the <xref:System.Text.Json.Utf8JsonReader.GetString> method, then parse the value using custom logic.

The following example shows how a custom <xref:System.DateTimeOffset> text representation can be retrieved using the <xref:System.Text.Json.Utf8JsonReader.GetString> method,
then parsed using <xref:System.DateTimeOffset.ParseExact(System.String,System.String,System.IFormatProvider)>:
Expand All @@ -146,24 +148,23 @@ then parsed using <xref:System.DateTimeOffset.ParseExact(System.String,System.St

### Date and time components

The extended ISO 8601-1:2019 profile implemented in <xref:System.Text.Json?displayProperty=fullName> defines the following components for
date and time representations. These components are used to define various supported levels of granularity
The extended ISO 8601-1:2019 profile implemented in <xref:System.Text.Json?displayProperty=fullName> defines the following components for date and time representations. These components are used to define various supported levels of granularity
when parsing and formatting <xref:System.DateTime> and <xref:System.DateTimeOffset> representations.

| Component | Format | Description |
|-----------------|-----------------------------|---------------------------------------------------------------------------------|
| Year | "yyyy" | 0001-9999 |
| Month | "MM" | 01-12 |
| Day | "dd" | 01-28, 01-29, 01-30, 01-31 based on month/year. |
| Hour | "HH" | 00-23 |
| Minute | "mm" | 00-59 |
| Second | "ss" | 00-59 |
| Second fraction | "FFFFFFF" | Minimum of one digit, maximum of 16 digits. |
| Time offset | "K" | Either "Z" or "('+'/'-')HH':'mm". |
| Partial time | "HH':'mm':'ss[FFFFFFF]" | Time without UTC offset information. |
| Full date | "yyyy'-'MM'-'dd" | Calendar date. |
| Full time | "'Partial time'K" | UTC of day or Local time of day with the time offset between local time and UTC.|
| Date time | "'Full date''T''Full time'" | Calendar date and time of day, for example, 2019-07-26T16:59:57-05:00. |
| Component | Format | Description |
|-----------------|-------------------------|-------------------------------------------------|
| Year | "yyyy" | 0001-9999 |
| Month | "MM" | 01-12 |
| Day | "dd" | 01-28, 01-29, 01-30, 01-31 based on month/year. |
| Hour | "HH" | 00-23 |
| Minute | "mm" | 00-59 |
| Second | "ss" | 00-59 |
| Second fraction | "FFFFFFF" | Minimum of one digit, maximum of 16 digits. |
| Time offset | "K" | Either "Z" or "('+'/'-')HH':'mm". |
| Partial time | "HH':'mm':'ss[FFFFFFF]" | Time without UTC offset information. |
| Full date | "yyyy'-'MM'-'dd" | Calendar date. |
| Full time | "'Partial time'K" | UTC of day or Local time of day with the time offset between local time and UTC.|
| Date time | "'Full date''T''Full time'" | Calendar date and time of day, for example, 2019-07-26T16:59:57-05:00. |

### Support for parsing

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ The `System.Text.Json` namespace provides functionality for serializing to and d
* .NET Framework 4.6.2 and later versions
* .NET Core 2.0, 2.1, and 2.2

>[!TIP]
> You can use AI assistance to [migrate from `Newtonsoft.Json` with GitHub Copilot](#use-github-copilot-to-migrate).
> [!TIP]
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-github-copilot-to-migrate).

`System.Text.Json` focuses primarily on performance, security, and standards compliance. It has some key differences in default behavior and doesn't aim to have feature parity with `Newtonsoft.Json`. For some scenarios, `System.Text.Json` currently has no built-in functionality, but there are recommended workarounds. For other scenarios, workarounds are impractical.

Expand Down Expand Up @@ -380,7 +380,7 @@ Starting in .NET 7, you can use the C# `required` modifier or the <xref:System.T
* The `DateTimeZoneHandling` setting can be used to serialize all `DateTime` values as UTC dates.
* The `DateFormatString` setting and `DateTime` converters can be used to customize the format of date strings.

<xref:System.Text.Json?displayProperty=fullName> supports ISO 8601-1:2019, including the RFC 3339 profile. This format is widely adopted, unambiguous, and makes round trips precisely. To use any other format, create a custom converter. For example, the following converters serialize and deserialize JSON that uses Unix epoch format with or without a time zone offset (values such as `/Date(1590863400000-0700)/` or `/Date(1590863400000)/`):
<xref:System.Text.Json> supports ISO 8601-1:2019, including the RFC 3339 profile. This format is widely adopted, unambiguous, and makes round trips precisely. To use any other format, create a custom converter. For example, the following converters serialize and deserialize JSON that uses Unix epoch format with or without a time zone offset (values such as `/Date(1590863400000-0700)/` or `/Date(1590863400000)/`):

:::code language="csharp" source="snippets/how-to-contd/csharp/CustomConverterUnixEpochDate.cs" id="ConverterOnly":::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Forecast

public class Program
{
public static void Main()
public static void Run()
{
Forecast forecast = new()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void Write(

public class Program
{
public static void Main()
public static void Run()
{
string json = @"{""x"":1,""y"":2,""Description"":null}";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class WeatherForecast

public class Program
{
public static void Main()
public static void Run()
{
string jsonString = """
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class MyReferenceHandler : ReferenceHandler

public class Program
{
public static void Main()
public static void Run()
{
Employee tyler = new()
{
Expand Down
Loading
Loading