CipherIS
asked on
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?
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
Error.jpg
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.
ASKER
How do I do that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I added an image of the class - minus private info
Crypto.jpg
Crypto.jpg
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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:
The way your class is built, you would need to to the following in order to call the method:
aes obj;
ojb.Encrypt("text")
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)
ASKER
fixed my problem