Skip to content

VB.NET: references to Shared fields/properties and class-qualified access are not resolved #2305

Closed

Description

@serkanince

Summary

VB.NET files are parsed (nodes show up as vbnet), but member access through the class name (AppSession.SessionId) does not produce a reference edge for Shared fields and Shared properties. codegraph callers returns 0 for them, and also for the class itself. Shared methods are resolved correctly.

In a real project this hides hundreds of usages that plain text search finds immediately, and makes impact / blast-radius output misleading.

Environment

CodeGraph 1.6.1 (Windows, official installer)
Node v26.10.0
OS Windows 11 Enterprise 10.0.26100
Language VB.NET (.NET Framework WinForms)
Setup codegraph init, no codegraph.json extension mappings

Minimal reproduction (synthetic code)

AppSession.vb

Public Class AppSession
    Public Shared SessionId As Guid = Guid.NewGuid()
    Public Shared Property CurrentUser As String
    Public Shared Function GetGreeting() As String
        Return "Hello " & CurrentUser
    End Function
End Class

Consumer.vb

Public Class Consumer
    Public Sub Run()
        Dim id As Guid = AppSession.SessionId
        AppSession.CurrentUser = "demo"
        Console.WriteLine(AppSession.GetGreeting())
    End Sub
End Class

Consumer2.vb

Public Class Consumer2
    Public Function Describe() As String
        Return AppSession.CurrentUser & AppSession.SessionId.ToString()
    End Function
End Class

Steps:

  1. Put the three files in an empty folder.
  2. Run codegraph init (result: 11 nodes, 9 edges).
  3. Run the callers commands below.
Command Result
codegraph callers GetGreeting 1 caller: Consumer.Run (Consumer.vb:2) ✅
codegraph callers SessionId 0 callers ❌
codegraph callers CurrentUser 0 callers ❌
codegraph callers AppSession 0 callers ❌

Expected

  • SessionId and CurrentUser list Consumer.Run and Consumer2.Describe as referencing symbols.
  • AppSession lists the classes that reference it.

Actual

Only the method call produces an edge. Field and property reads/writes through the class name produce none, so callers, impact and the blast-radius section of codegraph_explore under-report dependencies.

Impact on a real codebase

In a ~2,000-file VB.NET WinForms solution, a central static session class (Public Class with Public Shared members) is referenced from ~460 files according to grep.

  • codegraph callers <ClassName> returns only 6 results (all from one C# file).
  • codegraph callers <SharedField> returns 0.
  • codegraph callers <SharedMethod> works: 1,519 callers found.

So the problem looks specific to field/property access through the class name, not to the class being static.

Notes

  • Not tested: instance-qualified access, Imports-based access, Module members.
  • Happy to test a fix against our real codebase and report numbers.

Activity

  1. colbymchenry commented on Oct 5, 2026

    @colbymchenry
    Owner

    Thanks @serkanince for the report and the clear minimal repro.

    The fix is on main in #2355, building on the approach in #2321 by @ChrisPrapas. VB.NET used to record only calls, so a read or write through a class name, like AppSession.SessionId or AppSession.CurrentUser = "demo", produced no reference at all. It now links both the member and the class. On your three files, codegraph callers SessionId, callers CurrentUser and callers AppSession all list Consumer.Run and Consumer2.Describe. Before, they returned 0.

    The same now applies to:

    • Enum values like Mode.Fast
    • indexed Shared fields like AppSession.Items(0)
    • Shared functions named without parentheses, which count as calls. Under AddressOf or NameOf they stay plain references.

    The name is resolved the way VB.NET scopes it, through namespaces and Imports, including aliases. A local, parameter or field that only shares the class's name, which VB.NET's case-insensitivity makes easy to hit, is not mistaken for the class. On two public WinForms projects, SCrawler and staxrip, this added about 2,500 and 5,900 correct links, and none were removed.

    Not covered yet: reads through Me. or an instance variable (s.CurrentUser), and With blocks.

    This ships in the next release. Re-index after upgrading (codegraph index) to pick it up. You and @ChrisPrapas are both credited in the changelog. If you get a chance to run it on your ~2,000-file solution, the before and after numbers would be welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions