2

In VS 2015, when I click 'Find All References' on a class definition for a class that implements IDisposable, it returns MyBase.Finalize() for every class which implements IDisposable.

NOTE: This happens when I click 'Find All References' on the class definition itself (i.e. Public Class Test123). If I click 'Find All References' on the implementation (i.e. New Test123) then it only fetches instances which use that specific New constructor. This is also confusing. In VS 2010, the class definition itself and all implementations were grouped together in one list, but in 2015 they are NOT.

Refer to the screenshot below. Even when I mousehover over class Test123, it highlights the MyBase.Finalize() method for both Test123 and Test456

Visual Studio 2010 does NOT do this. Is this a bug, or a 'new feature'?

The difficulty this causes is that for the current project at work, we manually implement IDisposable for every class. So when I click 'Find All References' on any class, it takes 10-20 seconds to find the references, and then it displays thousands of instances of MyBase.Finalize() (one for every single class), and it's basically completely useless.

Screenshot (I can't directly insert pictures with my acct yet)

Public Class Form1
    Dim a As New Test123
    Dim b As New Test456
End Class

Public Class Test123
    Implements IDisposable

    Dim A As Double = 0

    'Dispose Implementation
    Dim mbDisposed As Boolean = False
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
    GC.SuppressFinalize(Me)
    End Sub
    Private Overloads Sub Dispose(ByVal lbDisposing As Boolean)
        If Not mbDisposed Then
            If lbDisposing Then
                'Dispose of all nullable objects
            End If
        End If
        mbDisposed = True
    End Sub
    Protected Overrides Sub Finalize()
        Dispose(False)
        MyBase.Finalize()
    End Sub
End Class

Public Class Test456
    Implements IDisposable

    Dim B As Double = 1

    'Dispose Implementation
    Dim mbDisposed As Boolean = False
    Public Overloads Sub Dispose() Implements IDisposable.Dispose
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
    Private Overloads Sub Dispose(ByVal lbDisposing As Boolean)
        If Not mbDisposed Then
            If lbDisposing Then
                'Dispose of all nullable objects
            End If
        End If
        mbDisposed = True
    End Sub
    Protected Overrides Sub Finalize()
        Dispose(False)
        MyBase.Finalize()
    End Sub
End Class
  • Refer to my conversation with MSDN help... Apparently this is the 'default behavior' in 2015. How can a list of 2000 'MyBase.Finalize()' entries possibly be helpful to anyone anywhere? https://social.msdn.microsoft.com/Forums/vstudio/en-US/e9de2132-63f2-4704-89b3-dd016b7ec055/find-all-references-on-classes-that-implement-idisposable-in-vs-2015-vbnet-does-not-work?forum=visualstudiogeneral#e9de2132-63f2-4704-89b3-dd016b7ec055 – Ninja Starfish Aug 03 '16 at 12:44

2 Answers2

2

For a given method for example, try to use "Call Hierarchy" on it to see 3 groups of calls:

  1. Calls to its "base" implementation
  2. Calls to its "override" implementations
  3. Calls to its direct (current class) implementation

enter image description here


enter image description here


Helping ?

MStack
  • 328
  • 3
  • 6
  • Sorry, but it does not. View Call Hierarchy doesn't seem to work when you use on a class definition. I can use it on methods and properties, but when i right-click the `Test123` next to `Public Class Test123`, it doesn't do anything. Am I not using it correctly? – Ninja Starfish Jan 25 '17 at 12:48
  • In fact, you have to right-click it exactly next to : `Private Overloads Sub Dispose(ByVal lbDisposing As Boolean)` Right-click not at class definition's level, but at method level... Helping ? – MStack Jan 30 '17 at 10:30
  • When I do this, it shows me the locations where `Dispose` is called. But that's not what I want. I want to see all the locations where the class `Test123` is referenced. I.e. it should return references to the lines `Dim a As New Test123` and `Public Class Test123`. I DON'T want to see anything related to `Dispose` and I DON'T want to see anything related to `Finalize` – Ninja Starfish Jan 30 '17 at 14:07
  • Refer to the link to the picture from the original post. The only thing that should be returned in the "Find All Symbols" window (in my opinion/understanding) at the bottom of the picture should be the final two entries. However it also returns entries from `Finalize`, which i DON'T want. And not only that, but it also returns the `Finalize` entries from EVERY CLASS which implements IDisposable, not just Test123 but also Test456! I don't want any of this, I just want the TWO locations where Test123 is referred to. – Ninja Starfish Jan 30 '17 at 14:14
  • Ok I understand now what you want. I think it could be some bug for VB.NET on visual studio 2015, because for my case, as C#.Net, I never seen that strange thing just for searching any class references and this is true also for any other things like variables, properties, etc... Could you check whether it does same thing for C# project on your VS2015 ? If no, but only on VB.Net, put this to Microsoft support team... – MStack Jan 31 '17 at 15:05
  • I don't use c# much, can't check it. I did open a thread on msdn forms [here](https://social.msdn.microsoft.com/Forums/vstudio/en-US/e9de2132-63f2-4704-89b3-dd016b7ec055/find-all-references-on-classes-that-implement-idisposable-in-vs-2015-vbnet-does-not-work?forum=visualstudiogeneral#2c707a32-4c4a-47e8-b9ee-349f1daa4e28) and i submitted a bug [here](https://connect.microsoft.com/VisualStudio/feedback/details/3090626). The bug is marked resolved. I downloaded the new 2017 RC visual studio and now there is a filter mechanism. If i select "Definition Only", then the first group (see next comment) – Ninja Starfish Feb 13 '17 at 12:56
  • contains the actual references that i'm looking for. All the other `Finalize()` methods are still there, but they are listed below in other groups. So as long as I can easily find the droids i'm looking for, i suppose all is well. – Ninja Starfish Feb 13 '17 at 13:03
0

I downloaded Visual Studio 2017 RC. The "Find All References" window now contains a filtering combo box. If i select "Group by: Definition Only", then the actual references I'm trying to find appear in the first "group" in the list.

All the Finalize() methods from every other class in the project in the project are still listed, but they are placed in separate groups below. So technically this bug still exists, but I am able to easily filter out the garbage that I don't want to see as shown in this snapshot