JetBrains Rider
 
2024.3
Get JetBrains Rider

Code inspection: Return value of a method annotated with [MustDisposeResource] is never disposed

Last modified: 25 September 2024

If you are using the [MustDisposeResourceAttribute] from JetBrains.Annotations to enforce resource disposal in the calling code, JetBrains Rider reports cases where there is a variable initialized with a constructor or a factory method returning a disposable resource, and that variable is not handled properly.

To avoid an incorrect handling of the disposable resource, JetBrains Rider suggests converting variable declaration into a using declaration or a using block: