-
Notifications
You must be signed in to change notification settings - Fork 6k
CA2025 Analyzer documentation #46051
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add this to the TOC file on this line?
author: steveberdy | ||
dev_langs: | ||
- CSharp | ||
- VB |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- VB |
...since you don't have a VB example, this isn't necessary.
|
||
## Rule description | ||
|
||
Unawaited tasks that use `IDisposable` instances may use those instances long after they have been disposed. Ensure tasks using those instances are completed before the instances are disposed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unawaited tasks that use `IDisposable` instances may use those instances long after they have been disposed. Ensure tasks using those instances are completed before the instances are disposed. | |
Unawaited tasks that use `IDisposable` instances might use those instances long after they've been disposed. Ensure tasks using those instances are completed before the instances are disposed. |
|
||
## Examples | ||
|
||
The following code snippets (and their VB equivalents) are violations of CA2025: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following code snippets (and their VB equivalents) are violations of CA2025: | |
The following code snippets (and their Visual Basic equivalents) are violations of CA2025: |
```csharp | ||
public Task DoSomethingAsync() | ||
{ | ||
// Using statements and using blocks can both be violations |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Using statements and using blocks can both be violations | |
// Using statements and using blocks can both be violations. |
var task = DoSomethingInternalAsync(disposable); | ||
// More code here | ||
dispose.Dispose(); | ||
// It's a violation if arguments are disposed before the task is awaited |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// It's a violation if arguments are disposed before the task is awaited | |
// It's a violation if arguments are disposed before the task is awaited. |
{ | ||
var disposable = new DisposableThing(); | ||
var task = DoSomethingInternalAsync(disposable); | ||
// More code here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// More code here | |
// More code here. |
Summary
Hey team, it's been a while! Here's documentation for another analyzer.
Analyzer PR here (already merged): dotnet/roslyn-analyzers#7549
Internal previews