Skip to content

Commit 19d9a8a

Browse files
authored
Document EXTOBS obsolete diagnostics for extensions (#49870)
1 parent 7d1b518 commit 19d9a8a

File tree

3 files changed

+132
-11
lines changed

3 files changed

+132
-11
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
---
2+
title: EXTOBS0001 warning
3+
description: Learn about the obsoletions that generate compile-time warning EXTOBS0001.
4+
ms.date: 11/12/2025
5+
f1_keywords:
6+
- extobs0001
7+
ai-usage: ai-assisted
8+
---
9+
# EXTOBS0001: IResourceMonitor is obsolete
10+
11+
The <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor?displayProperty=fullName> 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.
12+
13+
The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0001` at compile time.
14+
15+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor>
16+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceMonitoringOptions.CollectionWindow?displayProperty=nameWithType>
17+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceMonitoringOptions.SamplingInterval?displayProperty=nameWithType>
18+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceMonitoringBuilderExtensions>
19+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilization>
20+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitorBuilder>
21+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceUtilizationPublisher>
22+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.ISnapshotProvider>
23+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.Snapshot>
24+
- <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.SystemResources>
25+
- <xref:Microsoft.Extensions.DependencyInjection.ResourceMonitoringServiceCollectionExtensions.AddResourceMonitoring(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Action{Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitorBuilder})?displayProperty=nameWithType>
26+
27+
## Workarounds
28+
29+
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.
30+
31+
### Migration example
32+
33+
Old approach using `IResourceMonitor`:
34+
35+
```csharp
36+
services.AddResourceMonitoring();
37+
38+
// Inject and use IResourceMonitor
39+
public class MyService
40+
{
41+
private readonly IResourceMonitor _resourceMonitor;
42+
43+
public MyService(IResourceMonitor resourceMonitor)
44+
{
45+
_resourceMonitor = resourceMonitor;
46+
}
47+
48+
public void CheckResources()
49+
{
50+
var utilization = _resourceMonitor.GetUtilization(TimeSpan.FromSeconds(1));
51+
Console.WriteLine($"CPU: {utilization.CpuUsedPercentage}%");
52+
Console.WriteLine($"Memory: {utilization.MemoryUsedPercentage}%");
53+
}
54+
}
55+
```
56+
57+
New approach using metrics:
58+
59+
```csharp
60+
services.AddResourceMonitoring();
61+
62+
// Configure metrics collection.
63+
services.AddOpenTelemetry()
64+
.WithMetrics(builder =>
65+
{
66+
builder.AddMeter("Microsoft.Extensions.Diagnostics.ResourceMonitoring");
67+
builder.AddConsoleExporter();
68+
});
69+
```
70+
71+
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).
72+
73+
## Suppress a warning
74+
75+
If you must use the obsolete APIs, you can suppress the warning in code or in your project file.
76+
77+
To suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the warning.
78+
79+
```csharp
80+
// Disable the warning.
81+
#pragma warning disable EXTOBS0001
82+
83+
// Code that uses obsolete API.
84+
// ...
85+
86+
// Re-enable the warning.
87+
#pragma warning restore EXTOBS0001
88+
```
89+
90+
To suppress all the `EXTOBS0001` warnings in your project, add a `<NoWarn>` property to your project file.
91+
92+
```xml
93+
<Project Sdk="Microsoft.NET.Sdk">
94+
<PropertyGroup>
95+
...
96+
<NoWarn>$(NoWarn);EXTOBS0001</NoWarn>
97+
</PropertyGroup>
98+
</Project>
99+
```
100+
101+
For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings).
102+
103+
## See also
104+
105+
- [Diagnostic resource monitoring](../../core/diagnostics/diagnostic-resource-monitoring.md)
106+
- [`Microsoft.Extensions.Diagnostics.ResourceMonitoring` metrics](../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring)

docs/fundamentals/syslib-diagnostics/obsoletions-overview.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
---
22
title: Obsolete features in .NET 5+
33
description: Learn about APIs that are marked as obsolete in .NET 5 and later versions that produce SYSLIB compiler warnings.
4-
ms.date: 01/14/2025
4+
ms.date: 11/12/2025
55
ai-usage: ai-assisted
66
---
77

88
# Obsolete features in .NET 5+
99

1010
Starting in .NET 5, some APIs that are newly marked as obsolete make use of two new properties on <xref:System.ObsoleteAttribute>.
1111

12-
- The <xref:System.ObsoleteAttribute.DiagnosticId?displayProperty=nameWithType> 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`.
13-
12+
- The <xref:System.ObsoleteAttribute.DiagnosticId?displayProperty=nameWithType> 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`.
1413
- The <xref:System.ObsoleteAttribute.UrlFormat?displayProperty=nameWithType> property tells the compiler to include a URL link to learn more about the obsoletion.
1514

16-
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).
15+
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).
16+
17+
The following tables provide an index to obsolete APIs with custom diagnostic IDs in .NET 5 and later versions:
1718

18-
## Reference
19+
- [SYSLIB obsoletions](#syslib-obsoletions)
20+
- [EXTOBS obsoletions](#extobs-obsoletions)
1921

20-
The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+.
22+
## SYSLIB obsoletions
23+
24+
The following table lists the `SYSLIB0XXX` obsoletions in .NET 5+.
2125

2226
| Diagnostic ID | Warning or error | Description |
2327
|---------------|------------------|-------------|
@@ -84,9 +88,17 @@ The following table provides an index to the `SYSLIB0XXX` obsoletions in .NET 5+
8488
| [SYSLIB0061](syslib0061.md) | Warning | The `Queryable` <xref:System.Linq.Queryable.MaxBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> and <xref:System.Linq.Queryable.MinBy``2(System.Linq.IQueryable{``0},System.Linq.Expressions.Expression{System.Func{``0,``1}},System.Collections.Generic.IComparer{``0})?displayProperty=nameWithType> taking an `IComparer<TSource>` are obsolete. Use the new ones that take an `IComparer<TKey>`. |
8589
| [SYSLIB0062](syslib0062.md) | Warning | <xref:System.Xml.Xsl.XsltSettings.EnableScript?displayProperty=nameWithType> is obsolete. |
8690

91+
## EXTOBS obsoletions
92+
93+
The following table lists the `EXTOBS0XXX` obsoletions from the `Microsoft.Extensions` libraries.
94+
95+
| Diagnostic ID | Warning or error | Description |
96+
|---------------|------------------|-------------|
97+
| [EXTOBS0001](extobs0001.md) | Warning | <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor> is obsolete and will be removed in a future version. Consider using [Resource Monitoring observable instruments](../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring). |
98+
8799
## Suppress warnings
88100

89-
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 `<NoWarn>` 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.
101+
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 `<NoWarn>` 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.
90102

91103
To suppress the warnings in code:
92104

@@ -123,7 +135,6 @@ To suppress the warnings in a project file:
123135
124136
## See also
125137

126-
- [API obsoletions with non-default diagnostic IDs (.NET 5)](../../core/compatibility/core-libraries/5.0/obsolete-apis-with-custom-diagnostics.md)
127-
- [API obsoletions with non-default diagnostic IDs (.NET 6)](../../core/compatibility/core-libraries/6.0/obsolete-apis-with-custom-diagnostics.md)
128-
- [API obsoletions with non-default diagnostic IDs (.NET 7)](../../core/compatibility/core-libraries/7.0/obsolete-apis-with-custom-diagnostics.md)
129138
- [API obsoletions with non-default diagnostic IDs (.NET 8)](../../core/compatibility/core-libraries/8.0/obsolete-apis-with-custom-diagnostics.md)
139+
- [API obsoletions with non-default diagnostic IDs (.NET 9)](../../core/compatibility/core-libraries/9.0/obsolete-apis-with-custom-diagnostics.md)
140+
- [API obsoletions with non-default diagnostic IDs (.NET 10)](../../core/compatibility/core-libraries/10.0/obsolete-apis.md)

docs/navigate/tools-diagnostics/toc.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3936,7 +3936,7 @@ items:
39363936
- name: Obsoletions
39373937
items:
39383938
- name: Overview
3939-
displayName: syslib, obsolete, obsoletion
3939+
displayName: syslib, extobs, obsolete, obsoletion
39403940
href: ../../fundamentals/syslib-diagnostics/obsoletions-overview.md
39413941
- name: SYSLIB0001
39423942
href: ../../fundamentals/syslib-diagnostics/syslib0001.md
@@ -4170,6 +4170,10 @@ items:
41704170
- name: SYSLIB1230
41714171
href: ../../fundamentals/syslib-diagnostics/syslib1230.md
41724172
displayProperty: syslib1230, syslib1231, syslib1232, syslib1233, syslib1234, syslib1235, syslib1236, syslib1237, syslib1238, syslib1239
4173+
- name: EXTOBS diagnostics
4174+
items:
4175+
- name: EXTOBS0001
4176+
href: ../../fundamentals/syslib-diagnostics/extobs0001.md
41734177
- name: API compatibility
41744178
items:
41754179
- name: Overview

0 commit comments

Comments
 (0)