Avatar of p-plater
p-platerFlag for Australia asked on

Reference to a non-shared member requires an object reference.

I'm missing something basic but I can't work it out..

I have a Public Class with a Public Function inside it (This is in a BLL DLL)

Public Class CompanySearch
    Public Function Search(ByVal searchText As String) As CompanyName
        Dim companySearchList As New CompanyNameCollection(searchText, False)

        If companySearchList.Count = 1 Then
            Dim company As CompanyName = companySearchList.Item(0)
            Return company
        Else
            Using CompanySearchForm = New CompanySearch()
                With CompanySearchForm
                    .SearchTextBox.Text = searchText
                    .SearchResultDataGridView.DataSource = companySearchList
                    .ShowDialog()
                End With
                Dim company As CompanyName = companySearchList.Item(0)
                Return company
            End Using
        End If
    End Function
End Class

Open in new window


I am trying to call it from the UI

Dim company As New CompanyName
company = CompanySearch.Search(CompanyNameTextBox.Text)

Open in new window


But I am getting the "Reference to a non-shared member requires an object reference" Error.
I thought I was giving it an Object Reference by using a Instance of the CompanyName Class?
Visual Basic.NET

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
kaufmed

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
p-plater

Is there any Serious Security Problem with declaring Class Methods as Shared?
ASKER
p-plater

Thanks

I thought I had created an instance of the Class - But I was using a different Class :(
kaufmed

Is there any Serious Security Problem with declaring Class Methods as Shared?
Not that I am aware of. Why would you think there would be?
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy