Skip to content
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

Regression: Analyzer 'SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce' threw an exception #606

Closed
JochenKalmbach opened this issue Jul 27, 2017 · 1 comment

Comments

@JochenKalmbach
Copy link

Description

There is an Regression in the alanyzer in Version 6.2.0.2536 compared to the previous Version (6.1.0.2359).

Repro steps

  1. Create a C# Console App (.NET 4.6.1)
  2. Assign the SonarAnalyzer.CSharp" version=6.2.0.2536
  3. Insert the following code:
using System;
using System.Threading;
namespace SonarAnalyzer.CSharp.Tests
{
    sealed class ObjectsShouldNotBeDisposedMoreThanOnceException : IDisposable
    {
        static void Main()
        {
            return;
        }
        SemaphoreSlim _Semaphore;

        public ObjectsShouldNotBeDisposedMoreThanOnceException()
        {
            _Semaphore = new SemaphoreSlim(1, 1);
        }
        public void Dispose()
        {
            _Semaphore?.Dispose();
            _Semaphore = null;
        }
    }
}

Expected behavior

Th analyzer should not throw an exception; instead it should issue a warning..

Actual behavior

Duringthe analysing process the analyzer throws an exception:
1>CSC : warning AD0001: Analyzer 'SonarAnalyzer.Rules.CSharp.ObjectsShouldNotBeDisposedMoreThanOnce' threw an exception of type 'System.InvalidCastException' with message 'Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.MemberBindingExpressionSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.MemberAccessExpressionSyntax'.'.

Known workarounds

Revoke to Version 6.1.0.2359

Related information

  • Visual Studio Version: 2017
@Evangelink
Copy link
Contributor

Hi @JochenKalmbach!

Thanks for reporting this issue. It should be fixed by #587.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants