Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 370
Dave Mackey Avatar asked Nov 19 '12 21:11

Dave Mackey


People also ask

What is reference to a non shared member requires an object reference?

You have referenced a non-shared member within your code and failed to supply an object reference. You cannot use the class name itself to qualify a member that is not shared. The instance must first be declared as an object variable and then referenced by the variable name.

What is object reference not set to an instance?

The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs.


2 Answers

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)

like image 109
Tim Schmelter Avatar answered Sep 20 '22 17:09

Tim Schmelter


Go to the Declaration of the desired object and mark it Shared.

Friend Shared WithEvents MyGridCustomer As Janus.Windows.GridEX.GridEX

like image 35
Pastor Hampande Avatar answered Sep 19 '22 17:09

Pastor Hampande