• 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

        Try
            _login.ConnectionString = _connStr
            _login.UserId = txtUserName.Text
            _login.Password = Encrypt
                              (txtPassword.Text.ToString())
        Catch

        End Try

Open in new window

Error.jpg
0
CipherIS
Asked:
CipherIS
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.
0
 
CipherISAuthor Commented:
How do I do that?
0
 
käµfm³d 👽Commented:
What is the name of the class where you defined Encrypt and Decrypt?
0
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
Crypto.jpg
0
 
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"
0
 
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;
ojb.Encrypt("text")

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

0
 
CipherISAuthor Commented:
fixed my problem
0

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