• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 364
  • Last Modified:

Reference to a non-shared member requires an object reference

I added sample code below and an image.  I have a DLL that i created which encrypts / decrypts a string.  When I add    Encrypts( some text ) I receive "Reference to a non-shared member requires an object reference" error.  Without the encrypt I do not recevie the error.

Any idea how to resolve?
Protected Sub btnLogin_Click(ByVal sender As Object, 
      ByVal e As EventArgs) Handles btnLogin.Click

   Dim _connStr As String = ConfigurationManager.ConnectionStrings("DBASE").ToString()

    Dim _login As New BOL.Login
    Dim ds As New DataSet
    If Page.IsValid Then

            _login.ConnectionString = _connStr
            _login.UserId = txtUserName.Text
            _login.Password = Encrypt

        End Try

Open in new window

2 Solutions
käµfm³d 👽Commented:
You didn't post the code that defines your Encrypt and Decrypt methods (for obvious reasons, I'm sure), but it sounds like you didn't declare these methods as Shared, so they are instance methods--which means you need to create an instance of the class which houses these methods. Call the methods against the instance rather than as standalone functions.
CipherISAuthor Commented:
How do I do that?
käµfm³d 👽Commented:
What is the name of the class where you defined Encrypt and Decrypt?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

CipherISAuthor Commented:
I added an image of the class - minus private info
Mike TomlinsonMiddle School Assistant TeacherCommented:
So, as stated by kaufmed, you need to create an instance of your "aes" class:

    aes crypto = new aes();
    _login.Password = crypto.Encrypt(txtPassword.Text.ToString()) // <-- here we are using our instance "crypto"
Jacques Bourgeois (James Burger)Commented:
By default, when you create a method in a class, you need an object to call it.

The way your class is built, you would need to to the following in order to call the method:
aes obj;

Open in new window

In order to be able to call a method directly without having to declare a variable, as you do in your Click event, you need to declare the method as static (shared):
public static string Encrypt (string Data)

Open in new window

CipherISAuthor Commented:
fixed my problem

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now