Roslyn-analyzers: CA2213 warning for not disposing a timer, but I do.

Created on 6 Jul 2020  路  5Comments  路  Source: dotnet/roslyn-analyzers

_This issue has been moved from a ticket on Developer Community._


I get the following warning from the compiler:

Warning CA2213 'SplashScreen' contains field 'splashScreenTimer' that is of IDisposable type 'Timer', but it is never disposed. Change the Dispose method on 'SplashScreen' to call Close or Dispose on this field. ChumsMailer C:\gitrepos\ChumsMailer\Dialogs\SplashScreen.cs

I do have a call to Dispose in my code for the timer which my log and debugger confirm is being called. I attach a screen shot of the relevant code.


Original Comments

Visual Studio Feedback System on 7/3/2020, 01:42 AM:

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

Visual Studio Feedback System on 7/6/2020, 10:19 AM:

Thank you for sharing your feedback! Our teams prioritize action on product issues with broad customer impact. See details at: https://docs.microsoft.com/en-us/visualstudio/ide/report-a-problem?view=vs-2019#faq. In case you need answers to common questions or need assisted support, be sure to use https://visualstudio.microsoft.com/vs/support/. We鈥檒l keep you posted on any updates to this feedback.


Original Solutions

(no solutions)

Area-Microsoft.NetCore.Analyzers Bug False_Positive Resolution-Fixed

All 5 comments

@mavasani The user is talking about some screenshot but I don't see any. If you do see some on your side, would you mind sharing it here?

With only the description there is no way to actually see if there is any problem going-on.

@martincostello That's interesting... Looking at the files this is clearly a FP but I am having some trouble to understand what's going wrong. Could you confirm that the following snippet doesn't raise the issue:

public sealed class DisposableClass : IDisposable
    {
        public void Dispose() { }
    }

    public sealed class Class1 : IDisposable
    {
        private readonly DisposableClass _d = new DisposableClass();
        private bool _disposed;

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        private void Dispose(bool disposing)
        {
            if (!_disposed)
            {
                if (disposing)
                {
                    // Dispose of managed resources
                    _d.Dispose();
                }

                _disposed = true;
            }
        }
    }

I forgot to come back to this issue and update it, but these false positives resolved themselves after updating to 5.0 RC1.

I will close this issue then as there is no feedback on the original issue.

Was this page helpful?
0 / 5 - 0 ratings