Reference to a non-shared member requires an object reference occurs when calling public sub

Dave Mackey picture Dave Mackey · Nov 19, 2012 · Viewed 122.5k times · Source

I have a Public Class "General" in which is a Public Sub "updateDynamics". When I attempt to reference it in the code-behind for a page like so:

updateDynamics(get_prospect.dynamicsID)

I get the following error:

reference to a non-shared member requires an object reference

Answer

Tim Schmelter picture Tim Schmelter · Nov 19, 2012

You either have to make the method Shared or use an instance of the class General:

Dim gen = New General()
gen.updateDynamics(get_prospect.dynamicsID)

or

General.updateDynamics(get_prospect.dynamicsID)

Public Shared Sub updateDynamics(dynID As Int32)
    ' ... '
End Sub

Shared(VB.NET)