diff --git a/docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj b/docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj index a6f28d640889a..8076e05d18dc3 100644 --- a/docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj +++ b/docs/ai/quickstarts/snippets/function-calling/openai/FunctionCallingAI.csproj @@ -8,10 +8,10 @@ - - - - + + + + diff --git a/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/ExtensionsAzureOpenAI.csproj b/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/ExtensionsAzureOpenAI.csproj index d15bd0545bd0f..601219c3b6fbe 100644 --- a/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/ExtensionsAzureOpenAI.csproj +++ b/docs/ai/quickstarts/snippets/prompt-completion/azure-openai/ExtensionsAzureOpenAI.csproj @@ -10,9 +10,9 @@ - - - + + + diff --git a/docs/core/diagnostics/snippets/resource-monitoring/resource-monitoring.csproj b/docs/core/diagnostics/snippets/resource-monitoring/resource-monitoring.csproj index 37ad5cf099f55..40f65e6c216e4 100644 --- a/docs/core/diagnostics/snippets/resource-monitoring/resource-monitoring.csproj +++ b/docs/core/diagnostics/snippets/resource-monitoring/resource-monitoring.csproj @@ -12,7 +12,7 @@ - + diff --git a/docs/core/extensions/dependency-injection/snippets/console-ienumerable/console-di-ienumerable.csproj b/docs/core/extensions/dependency-injection/snippets/console-ienumerable/console-di-ienumerable.csproj index f78753e0f767b..5db61a5b48163 100644 --- a/docs/core/extensions/dependency-injection/snippets/console-ienumerable/console-di-ienumerable.csproj +++ b/docs/core/extensions/dependency-injection/snippets/console-ienumerable/console-di-ienumerable.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/docs/core/extensions/snippets/logging/console-formatter-simple/console-formatter-simple.csproj b/docs/core/extensions/snippets/logging/console-formatter-simple/console-formatter-simple.csproj index 0e9db4f790d2e..7283b8d295435 100644 --- a/docs/core/extensions/snippets/logging/console-formatter-simple/console-formatter-simple.csproj +++ b/docs/core/extensions/snippets/logging/console-formatter-simple/console-formatter-simple.csproj @@ -9,8 +9,8 @@ - - + + diff --git a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md index 16a7bb4cbf08c..8e5a690d88834 100644 --- a/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md +++ b/docs/core/testing/unit-testing-mstest-writing-tests-assertions.md @@ -3,7 +3,8 @@ title: MSTest assertions description: Learn about MSTest assertions including Assert, StringAssert, and CollectionAssert classes for validating test results. author: Evangelink ms.author: amauryleve -ms.date: 07/15/2025 +ms.date: 06/04/2026 +ai-usage: ai-assisted --- # MSTest assertions @@ -20,8 +21,8 @@ MSTest provides three assertion classes: | `StringAssert` | String-specific assertions for patterns, substrings, and comparisons. | | `CollectionAssert` | Collection assertions for comparing and validating collections. | -> [!TIP] -> When functionality exists in both `Assert` and `StringAssert`/`CollectionAssert`, prefer the `Assert` class. The `Assert` class provides better discoverability and is the recommended choice for new code. `StringAssert` and `CollectionAssert` are maintained for backward compatibility. +> [!IMPORTANT] +> For new code, always use the `Assert` class. The `StringAssert` and `CollectionAssert` classes are likely to be deprecated in a future release. They're maintained primarily for backward compatibility, but they're not recommended because splitting assertions across three types hurts discoverability. All assertion methods accept an optional message parameter that displays when the assertion fails, helping you identify the cause: @@ -107,8 +108,8 @@ public async Task AssertExamples() Use the class to compare and examine strings. -> [!NOTE] -> All `StringAssert` methods have equivalents in the `Assert` class. Prefer the `Assert` methods for better discoverability. The `StringAssert` class is maintained for backward compatibility. +> [!WARNING] +> The `StringAssert` class is likely to be deprecated in a future release. It's maintained for backward compatibility only and isn't recommended for new code. All `StringAssert` methods have equivalents on the `Assert` class, which offers better discoverability. To migrate existing usages, see analyzer [MSTEST0046](mstest-analyzers/mstest0046.md). Available APIs are: @@ -122,8 +123,8 @@ Available APIs are: Use the class to compare collections of objects, or to verify the state of a collection. -> [!NOTE] -> When an equivalent method exists in the `Assert` class (such as `Assert.Contains`, `Assert.DoesNotContain`), prefer using `Assert` for better discoverability. The `CollectionAssert` class is maintained primarily for backward compatibility. +> [!WARNING] +> The `CollectionAssert` class is likely to be deprecated in a future release. It's maintained primarily for backward compatibility and isn't recommended for new code. When an equivalent method exists on `Assert` (such as `Assert.Contains`, `Assert.DoesNotContain`, or `Assert.HasCount`), use `Assert` for better discoverability. Available APIs are: @@ -139,17 +140,68 @@ Available APIs are: - - +## Create custom assertions with `Assert.That` + +The built-in assertion methods don't cover every scenario. To extend the assertion infrastructure with your own checks, MSTest exposes the singleton property as an extensibility hook. You add custom assertions as C# extension methods on the `Assert` instance type, and callers invoke them with the familiar `Assert.That.MyAssertion(...)` syntax. + +For better discoverability, organize project-wide assertions in a dedicated static class. Custom assertions reached through `Assert.That` show up alongside the built-in methods in IntelliSense, so consumers don't have to remember a separate helper type. + +### Author a custom assertion + +Add an extension method that targets the `Assert` type and throws when the condition fails: + +```csharp +using System; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +public static class CustomAssertExtensions +{ + public static void IsPrime(this Assert assert, int value) + { + if (value < 2 || Enumerable.Range(2, (int)Math.Sqrt(value) - 1).Any(i => value % i == 0)) + { + throw new AssertFailedException($"Assert.That.IsPrime failed. Value <{value}> is not a prime number."); + } + } +} +``` + +### Use a custom assertion + +After you import the namespace that contains your extension methods, call your custom assertion through `Assert.That`: + +```csharp +[TestMethod] +public void Compute_ReturnsPrime() +{ + int result = _calculator.NextPrime(10); + Assert.That.IsPrime(result); +} +``` + +### Extension hooks on `StringAssert` and `CollectionAssert` + +The and properties expose the same singleton pattern for backward compatibility. For new custom assertions, always target `Assert.That`. Otherwise, your helpers inherit the same discoverability problems as the legacy classes, and they'll need migration if `StringAssert` and `CollectionAssert` are deprecated. + +### `Assert.That` property versus `Assert.That(...)` method + +> [!NOTE] +> Don't confuse the `Assert.That` singleton *property*—used as an extensibility hook—with the `Assert.That(() => condition)` *method* added in MSTest 3.8. The latter accepts a Boolean expression and produces detailed failure messages by analyzing the expression tree (for example, `Assert.That(() => order.Total > 0)`). The two APIs share a name but serve different purposes. + ## Best practices -1. **Use specific assertions**: Prefer `AreEqual` over `IsTrue(a == b)` for better failure messages. +- **Use specific assertions**: Prefer `AreEqual` over `IsTrue(a == b)` for better failure messages. + +- **Include descriptive messages**: Help identify failures quickly with clear assertion messages. -1. **Include descriptive messages**: Help identify failures quickly with clear assertion messages. +- **Test one thing at a time**: Each test method should verify a single behavior. -1. **Test one thing at a time**: Each test method should verify a single behavior. +- **Use `Throws`/`ThrowsExactly` for exceptions**: In MSTest v3.8+, prefer `Assert.Throws`, `Assert.ThrowsExactly`, and their async counterparts (`ThrowsAsync`, `ThrowsExactlyAsync`) over the `ExpectedException` attribute. -1. **Use `Throws`/`ThrowsExactly` for exceptions**: In MSTest v3.8+, prefer `Assert.Throws`, `Assert.ThrowsExactly`, and their async counterparts (`ThrowsAsync`, `ThrowsExactlyAsync`) over the `ExpectedException` attribute. +- **Prefer `Assert` over `StringAssert`/`CollectionAssert`**: For better discoverability and consistency, use the `Assert` class. The `StringAssert` and `CollectionAssert` classes are likely to be deprecated in a future release. -1. **Prefer `Assert` over `StringAssert`/`CollectionAssert`**: When functionality exists in both classes, use the `Assert` class for better discoverability and consistency. +- **Extend `Assert.That` for custom assertions**: For consistent discoverability, add custom assertions as extension methods on `Assert` and invoke them through `Assert.That`. Don't target `StringAssert.That` or `CollectionAssert.That` in new code. ## Related analyzers diff --git a/docs/core/tools/enable-tab-autocomplete.md b/docs/core/tools/enable-tab-autocomplete.md index 85baf215df6e2..eae13e9d15431 100644 --- a/docs/core/tools/enable-tab-autocomplete.md +++ b/docs/core/tools/enable-tab-autocomplete.md @@ -91,11 +91,11 @@ dotnet completions script fish | source #### Nushell -Add the following to the beginning of your `config.nu` file: +Add the following line(s) to your `config.nu` file: ```nu -dotnet completions script nushell | save -f ~/.local/share/nushell/completions/dotnet.nu -use ~/.local/share/nushell/completions/dotnet.nu * +mkdir ($nu.data-dir | path join "vendor/autoload") # Only add this line if not already present in your config. +dotnet completions script nushell | save -f ($nu.data-dir | path join "vendor/autoload/dotnet-completions.nu") ``` ## Dynamic completion scripts (all versions) @@ -115,7 +115,9 @@ pack If that command doesn't work, make sure that .NET Core 2.0 SDK or later is installed. If it's installed but that command still doesn't work, make sure that the `dotnet` command resolves to a version of .NET Core 2.0 SDK or later. Use the `dotnet --version` command to see what version of `dotnet` your current path is resolving to. For more information, see [Select the .NET version to use](../versions/selection.md). -### PowerShell +### Configure shells to use native completions + +#### PowerShell To add tab completion to **PowerShell** for the .NET CLI, create or edit the profile stored in the variable `$PROFILE`. For more information, see [How to create your profile](/powershell/module/microsoft.powershell.core/about/about_profiles#how-to-create-a-profile) and [Profiles and execution policy](/powershell/module/microsoft.powershell.core/about/about_profiles#profiles-and-execution-policy). @@ -131,9 +133,9 @@ Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock { } ``` -### bash +#### Bash -To add tab completion to your **bash** shell for the .NET CLI, add the following code to your `.bashrc` file: +Add the following code to your `.bashrc` file: ```bash # bash parameter completion for the dotnet CLI @@ -151,9 +153,9 @@ function _dotnet_bash_complete() complete -f -F _dotnet_bash_complete dotnet ``` -### zsh +#### Zsh -To add tab completion to your **zsh** shell for the .NET CLI, add the following code to your `.zshrc` file: +Add the following code to your `.zshrc` file: ```zsh # zsh parameter completion for the dotnet CLI @@ -176,43 +178,26 @@ _dotnet_zsh_complete() compdef _dotnet_zsh_complete dotnet ``` -### fish +#### Fish -To add tab completion to your **fish** shell for the .NET CLI, add the following code to your `config.fish` file: +Add the following code to your `config.fish` file: ```fish complete -f -c dotnet -a "(dotnet complete (commandline -cp))" ``` -### nushell +#### Nushell -To add tab completion to your **nushell** for .NET CLI, add the following to the beginning of your `config.nu` file: +Add the following code to your `config.nu` file: ```nu -let external_completer = { |spans| - { - dotnet: { || - dotnet complete ( - $spans | skip 1 | str join " " - ) | lines - } - } | get $spans.0 | each { || do $in } +def "nu-complete dotnet" [context: string] { + ^dotnet complete $"($context)" | lines } -``` - -And then in the `config` record, find the `completions` section and add the `external_completer` that was defined earlier to `external`: -```nu -let-env config = { - # your options here - completions: { - # your options here - external: { - # your options here - completer: $external_completer # add it here - } - } -} +export extern "dotnet" [ + ...command: string@"nu-complete dotnet" +] ``` ## Completion examples diff --git a/docs/core/tools/sdk-errors/index.md b/docs/core/tools/sdk-errors/index.md index d608cf78d4362..35401e6bcc103 100644 --- a/docs/core/tools/sdk-errors/index.md +++ b/docs/core/tools/sdk-errors/index.md @@ -382,3 +382,4 @@ This list is a complete list of the errors that you might get from the .NET SDK |[NETSDK1238](netsdk1238.md)|The current .NET SDK ({0}) has known vulnerabilities ({1}).{2} See | |[NETSDK1239](netsdk1239.md)|The current .NET SDK ({0}) is end of life as of {1}. It will receive no further security updates: | |[NETSDK1240](netsdk1240.md)|The current .NET SDK ({0}) has no newer release in its feature band. Update to version {1}: | +|[NETSDK1242](netsdk1242.md)|Building {0} projects with the Mono runtime is not supported in .NET 11.0 and later. Use the CoreCLR runtime or target .NET 10.0.| diff --git a/docs/core/tools/sdk-errors/netsdk1242.md b/docs/core/tools/sdk-errors/netsdk1242.md new file mode 100644 index 0000000000000..b41e3aabaf210 --- /dev/null +++ b/docs/core/tools/sdk-errors/netsdk1242.md @@ -0,0 +1,27 @@ +--- +title: "NETSDK1242: Building projects with the Mono runtime is not supported in .NET 11.0 and later" +description: Learn how to resolve build error NETSDK1242, which reports that the Mono runtime is not supported for the target mobile platform in .NET 11.0 and later. +ms.topic: error-reference +ms.date: 06/16/2026 +ai-usage: ai-assisted +f1_keywords: +- NETSDK1242 +--- +# NETSDK1242: Building projects with the Mono runtime is not supported in .NET 11.0 and later + +This error indicates that the project selects the Mono runtime (the `UseMonoRuntime` property is set to `true`) for a mobile target platform while targeting .NET 11.0 or later, where the Mono runtime is no longer supported for that platform. The full error message is similar to the following example: + +> NETSDK1242: Building ios projects with the Mono runtime is not supported in .NET 11.0 and later. Use the CoreCLR runtime or target .NET 10.0. + +The error applies to the `android`, `ios`, `maccatalyst`, and `tvos` target platforms. + +## Resolve the error + +Choose one of the following options: + +- Build the project with the CoreCLR runtime. Remove the `UseMonoRuntime` property from the project, or set it to `false`. +- If the project requires the Mono runtime, target .NET 10. Change the target framework to a .NET 10 mobile target framework moniker, for example `net10.0-android` or `net10.0-ios` + +## See also + +- [.NET SDK error and warning reference](index.md) diff --git a/docs/csharp/programming-guide/classes-and-structs/local-functions.md b/docs/csharp/programming-guide/classes-and-structs/local-functions.md index d8571d6778b11..758cb893eeb8c 100644 --- a/docs/csharp/programming-guide/classes-and-structs/local-functions.md +++ b/docs/csharp/programming-guide/classes-and-structs/local-functions.md @@ -18,6 +18,8 @@ helpviewer_keywords: - Finalizers - Other local functions +Beginning with C# 8.0, local function parameters can shadow local variables and parameters from an enclosing scope. + However, local functions can't be declared inside an expression-bodied member. > [!NOTE] diff --git a/docs/csharp/whats-new/csharp-version-history.md b/docs/csharp/whats-new/csharp-version-history.md index 52927bcffba90..329cff11c0d54 100644 --- a/docs/csharp/whats-new/csharp-version-history.md +++ b/docs/csharp/whats-new/csharp-version-history.md @@ -212,6 +212,7 @@ C# 8.0 is the first major C# release that specifically targets .NET Core. Some f - Positional patterns - [Using declarations](../language-reference/statements/using.md) - [Static local functions](../programming-guide/classes-and-structs/local-functions.md) +- Lambda expressions, anonymous methods, and local functions can declare parameters that shadow local variables and parameters from an enclosing scope. - [Disposable ref structs](../language-reference/builtin-types/ref-struct.md) - [Nullable reference types](../language-reference/builtin-types/nullable-reference-types.md) - [Asynchronous streams](../language-reference/statements/iteration-statements.md#await-foreach) diff --git a/docs/navigate/tools-diagnostics/toc.yml b/docs/navigate/tools-diagnostics/toc.yml index 0956f23e88898..a2862948c859f 100644 --- a/docs/navigate/tools-diagnostics/toc.yml +++ b/docs/navigate/tools-diagnostics/toc.yml @@ -99,6 +99,8 @@ items: href: ../../core/tools/sdk-errors/netsdk1239.md - name: NETSDK1240 href: ../../core/tools/sdk-errors/netsdk1240.md + - name: NETSDK1242 + href: ../../core/tools/sdk-errors/netsdk1242.md - name: BuildCheck rules items: - name: Index of rules diff --git a/docs/orleans/grains/snippets/transactions/Abstractions/Abstractions.csproj b/docs/orleans/grains/snippets/transactions/Abstractions/Abstractions.csproj index 91d3ed9daabf9..fbc756677e109 100644 --- a/docs/orleans/grains/snippets/transactions/Abstractions/Abstractions.csproj +++ b/docs/orleans/grains/snippets/transactions/Abstractions/Abstractions.csproj @@ -1,7 +1,7 @@ - + diff --git a/docs/orleans/grains/snippets/transactions/Client/Client.csproj b/docs/orleans/grains/snippets/transactions/Client/Client.csproj index fede8e757dd6c..cc2278e595fc1 100644 --- a/docs/orleans/grains/snippets/transactions/Client/Client.csproj +++ b/docs/orleans/grains/snippets/transactions/Client/Client.csproj @@ -5,7 +5,7 @@ - + diff --git a/docs/orleans/grains/snippets/transactions/Server/Server.csproj b/docs/orleans/grains/snippets/transactions/Server/Server.csproj index b28e7fbf738fa..115c1e042315f 100644 --- a/docs/orleans/grains/snippets/transactions/Server/Server.csproj +++ b/docs/orleans/grains/snippets/transactions/Server/Server.csproj @@ -5,7 +5,7 @@ - + diff --git a/samples/snippets/core/testing/unit-testing-using-dotnet-test/csharp/PrimeService.Tests/PrimeService.Tests.csproj b/samples/snippets/core/testing/unit-testing-using-dotnet-test/csharp/PrimeService.Tests/PrimeService.Tests.csproj index 734f7082665a1..c7737fdf6092a 100644 --- a/samples/snippets/core/testing/unit-testing-using-dotnet-test/csharp/PrimeService.Tests/PrimeService.Tests.csproj +++ b/samples/snippets/core/testing/unit-testing-using-dotnet-test/csharp/PrimeService.Tests/PrimeService.Tests.csproj @@ -7,7 +7,7 @@ - +