-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document EXTOBS obsolete diagnostics for extensions #49870
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
+132
−11
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
258dd3c
Initial plan
Copilot 88e2ef1
Add documentation for EXTOBS obsolete diagnostics
Copilot 9c804f0
remove second obsoletion for now
gewarren b4b8071
fix warnings
gewarren def99c6
add other affected apis
gewarren d76771a
Revise obsoletions overview for clarity and structure
gewarren d55509b
Updat display property for xref
gewarren a67ec83
Update docs/fundamentals/syslib-diagnostics/obsoletions-overview.md
gewarren 817ad33
Update docs/fundamentals/syslib-diagnostics/obsoletions-overview.md
gewarren 9482358
Update docs/fundamentals/syslib-diagnostics/extobs0001.md
gewarren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| --- | ||
| 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 <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor> interface and related APIs have been marked as 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. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The following APIs are marked obsolete. Use of these APIs generates warning `EXTOBS0001` at compile time. | ||
|
|
||
| - <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor?displayProperty=nameWithType> | ||
| - <xref:Microsoft.Extensions.Diagnostics.ResourceMonitoring.IResourceMonitor.GetUtilization(System.TimeSpan)?displayProperty=nameWithType> | ||
|
|
||
| ## 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. | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| services.AddOpenTelemetry() | ||
| .WithMetrics(builder => | ||
| { | ||
| builder.AddMeter("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); | ||
| builder.AddConsoleExporter(); // Or use any other exporter. | ||
gewarren marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| ``` | ||
|
|
||
| The resource monitoring metrics are automatically published and can be consumed by any OpenTelemetry-compatible metrics pipeline. For more information, see [Resource Monitoring observable instruments](../../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. | ||
gewarren marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```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 `<NoWarn>` property to your project file. | ||
|
|
||
| ```xml | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| ... | ||
| <NoWarn>$(NoWarn);EXTOBS0001</NoWarn> | ||
| </PropertyGroup> | ||
| </Project> | ||
| ``` | ||
|
|
||
| For more information, see [Suppress warnings](obsoletions-overview.md#suppress-warnings). | ||
|
|
||
| ## See also | ||
|
|
||
| - [Diagnostic resource monitoring](../../../core/diagnostics/diagnostic-resource-monitoring.md) | ||
| - [Built-in metrics - Resource Monitoring](../../../core/diagnostics/built-in-metrics-diagnostics.md#microsoftextensionsdiagnosticsresourcemonitoring) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.