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.

Error ID: BC30469

To correct this error

  1. Declare the instance as an object variable.

  2. Reference the instance by the variable name.

Imports System

Namespace Ecommerce
    Public Class Customer
        Private Property AccountNumber As Integer

        Public Sub New (accountNumber As Integer)
            AccountNumber = accountNumber
        End Sub

        Public Function GetAccountNumber ()
            return AccountNumber + accountNumber
        End Function
    End Class
End Namespace

Module Program
Sub Main(args As String())
        ' Declaring the instance as an object variable:
        Dim firstCustomer As New Ecommerce.Customer(1)
        Dim firstCustomerAccountNumber As Integer

        ' You must not use Ecommerce.Customer.GetAccountNumber() because you
        ' cannot access non-shared Function 'GetAccountNumber' in shared context.
        ' Otherwise, use the instance you've just created to call the function:
        firstCustomerAccountNumber = firstCustomer.GetAccountNumber()
        Console.WriteLine(firstCustomerAccountNumber)
    End Sub
End Module

See also