diff --git a/docs/fundamentals/syslib-diagnostics/extobs0001.md b/docs/fundamentals/syslib-diagnostics/extobs0001.md new file mode 100644 index 0000000000000..3d90b34ddf8f1 --- /dev/null +++ b/docs/fundamentals/syslib-diagnostics/extobs0001.md @@ -0,0 +1,106 @@ +--- +title: EXTOBS0001 warning +description: Learn about the obsoletions that generate compile-time warning EXTOBS0001. +ms.date: 11/12/2025 +f1_keywords: + - extobs0001 +ai-usage: ai-assisted +--- +# EXTOBS0001: IResourceMonitor is obsolete + +The interface and related APIs are obsolete starting in .NET 9. These APIs will be removed in a future version. The resource monitoring functionality has been replaced with a more efficient metrics-based approach using observable instruments. + +The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0001` at compile time. + +- +- +- +- +- +- +- +- +- +- +- + +## Workarounds + +Instead of using `IResourceMonitor`, switch to using resource monitoring metrics with observable instruments. The metrics-based approach provides the same resource utilization information (CPU, memory) but integrates better with modern observability systems like OpenTelemetry. + +### Migration example + +Old approach using `IResourceMonitor`: + +```csharp +services.AddResourceMonitoring(); + +// Inject and use IResourceMonitor +public class MyService +{ + private readonly IResourceMonitor _resourceMonitor; + + public MyService(IResourceMonitor resourceMonitor) + { + _resourceMonitor = resourceMonitor; + } + + public void CheckResources() + { + var utilization = _resourceMonitor.GetUtilization(TimeSpan.FromSeconds(1)); + Console.WriteLine($"CPU: {utilization.CpuUsedPercentage}%"); + Console.WriteLine($"Memory: {utilization.MemoryUsedPercentage}%"); + } +} +``` + +New approach using metrics: + +```csharp +services.AddResourceMonitoring(); + +// Configure metrics collection. +services.AddOpenTelemetry() + .WithMetrics(builder => + { + builder.AddMeter("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); + builder.AddConsoleExporter(); + }); +``` + +The resource monitoring metrics are automatically published and can be consumed by any OpenTelemetry-compatible metrics pipeline. For more information, see [`Microsoft.Extensions.Diagnostics.ResourceMonitoring` metrics](../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring). + +## Suppress a warning + +If you must use the obsolete APIs, you can suppress the warning in code or in your project file. + +To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning. + +```csharp +// Disable the warning. +#pragma warning disable EXTOBS0001 + +// Code that uses obsolete API. +// ... + +// Re-enable the warning. +#pragma warning restore EXTOBS0001 +``` + +To suppress all the `EXTOBS0001` warnings in your project, add a `` property to your project file. + +```xml + + + ... + $(NoWarn);EXTOBS0001 + + +``` + +For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings). + +## See also + +- [Diagnostic resource monitoring](../../core/diagnostics/diagnostic-resource-monitoring.md) +- [`Microsoft.Extensions.Diagnostics.ResourceMonitoring` metrics](../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring) diff --git a/docs/fundamentals/syslib-diagnostics/obsoletions-overview.md b/docs/fundamentals/syslib-diagnostics/obsoletions-overview.md index f6a8f835fbe53..aa8be162264b2 100644 --- a/docs/fundamentals/syslib-diagnostics/obsoletions-overview.md +++ b/docs/fundamentals/syslib-diagnostics/obsoletions-overview.md @@ -1,7 +1,7 @@ --- title: Obsolete features in .NET 5+ description: Learn about APIs that are marked as obsolete in .NET 5 and later versions that produce SYSLIB compiler warnings. -ms.date: 01/14/2025 +ms.date: 11/12/2025 ai-usage: ai-assisted --- @@ -9,15 +9,19 @@ ai-usage: ai-assisted Starting in .NET 5, some APIs that are newly marked as obsolete make use of two new properties on . -- The property tells the compiler to generate build warnings using a custom diagnostic ID. The custom ID allows for obsoletion warning to be suppressed specifically and separately from one another. In the case of the .NET 5+ obsoletions, the format for the custom diagnostic ID is `SYSLIB0XXX`. - +- The property tells the compiler to generate build warnings using a custom diagnostic ID. The custom ID allows for obsoletion warning to be suppressed specifically and separately from one another. In the case of the `System*` namespace obsoletions, the format for the custom diagnostic ID is `SYSLIB0XXX`. In the case of the `Microsoft.Extensions` obsoletions, the format for the custom diagnostic ID is `EXTOBS0XXX`. - The property tells the compiler to include a URL link to learn more about the obsoletion. -If you encounter build warnings or errors due to usage of an obsolete API, follow the specific guidance provided for the diagnostic ID listed in the [Reference](#reference) section. Warnings or errors for these obsoletions *can't* be suppressed using the [standard diagnostic ID (CS0618)](../../csharp/language-reference/compiler-messages/cs0618.md) for obsolete types or members; use the custom `SYSLIB0XXX` diagnostic ID values instead. For more information, see [Suppress warnings](#suppress-warnings). +If you encounter build warnings or errors due to usage of an obsolete API, follow the specific guidance provided for the diagnostic ID listed in the reference tables that follow. Warnings or errors for these obsoletions *can't* be suppressed using the [standard diagnostic ID (CS0618)](../../csharp/language-reference/compiler-messages/cs0618.md) for obsolete types or members; use the custom `SYSLIB0XXX` or `EXTOBS0XXX` diagnostic ID values instead. For more information, see [Suppress warnings](#suppress-warnings). + +The following tables provide an index to obsolete APIs with custom diagnostic IDs in .NET 5 and later versions: -## Reference +- [SYSLIB obsoletions](#syslib-obsoletions) +- [EXTOBS obsoletions](#extobs-obsoletions) -The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+. +## SYSLIB obsoletions + +The following table lists the `SYSLIB0XXX` obsoletions in .NET 5+. | Diagnostic ID | Warning or error | Description | |---------------|------------------|-------------| @@ -84,9 +88,17 @@ The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+ | [SYSLIB0061](syslib0061.md) | Warning | The `Queryable` and taking an `IComparer` are obsolete. Use the new ones that take an `IComparer`. | | [SYSLIB0062](syslib0062.md) | Warning | is obsolete. | +## EXTOBS obsoletions + +The following table lists the `EXTOBS0XXX` obsoletions from the `Microsoft.Extensions` libraries. + +| Diagnostic ID | Warning or error | Description | +|---------------|------------------|-------------| +| [EXTOBS0001](extobs0001.md) | Warning | is obsolete and will be removed in a future version. Consider using [Resource Monitoring observable instruments](../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring). | + ## Suppress warnings -It's recommended that you use an available workaround whenever possible. However, if you cannot change your code, you can suppress warnings through a `#pragma` directive or a `` project setting. If you must use the obsolete APIs and the `SYSLIB0XXX` diagnostic does not surface as an error, you can suppress the warning in code or in your project file. +It's recommended that you use an available workaround whenever possible. However, if you can't change your code, you can suppress warnings through a `#pragma` directive or a `` project setting. If you must use the obsolete APIs, and the `SYSLIB0XXX` or `EXTOBS0XXX` diagnostic doesn't surface as an error, you can suppress the warning in code or in your project file. To suppress the warnings in code: @@ -123,7 +135,6 @@ To suppress the warnings in a project file: ## See also -- [API obsoletions with non-default diagnostic IDs (.NET 5)](../../core/compatibility/core-libraries/5.0/obsolete-apis-with-custom-diagnostics.md) -- [API obsoletions with non-default diagnostic IDs (.NET 6)](../../core/compatibility/core-libraries/6.0/obsolete-apis-with-custom-diagnostics.md) -- [API obsoletions with non-default diagnostic IDs (.NET 7)](../../core/compatibility/core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md) - [API obsoletions with non-default diagnostic IDs (.NET 8)](../../core/compatibility/core-libraries/8.0/obsolete-apis-with-custom-diagnostics.md) +- [API obsoletions with non-default diagnostic IDs (.NET 9)](../../core/compatibility/core-libraries/9.0/obsolete-apis-with-custom-diagnostics.md) +- [API obsoletions with non-default diagnostic IDs (.NET 10)](../../core/compatibility/core-libraries/10.0/obsolete-apis.md) diff --git a/docs/navigate/tools-diagnostics/toc.yml b/docs/navigate/tools-diagnostics/toc.yml index ef7767c738afb..f9a73e90e8b12 100644 --- a/docs/navigate/tools-diagnostics/toc.yml +++ b/docs/navigate/tools-diagnostics/toc.yml @@ -3936,7 +3936,7 @@ items: - name: Obsoletions items: - name: Overview - displayName: syslib, obsolete, obsoletion + displayName: syslib, extobs, obsolete, obsoletion href: ../../fundamentals/syslib-diagnostics/obsoletions-overview.md - name: SYSLIB0001 href: ../../fundamentals/syslib-diagnostics/syslib0001.md @@ -4170,6 +4170,10 @@ items: - name: SYSLIB1230 href: ../../fundamentals/syslib-diagnostics/syslib1230.md displayProperty: syslib1230, syslib1231, syslib1232, syslib1233, syslib1234, syslib1235, syslib1236, syslib1237, syslib1238, syslib1239 + - name: EXTOBS diagnostics + items: + - name: EXTOBS0001 + href: ../../fundamentals/syslib-diagnostics/extobs0001.md - name: API compatibility items: - name: Overview