I'm trying to call a function in a class from a sub (page_load) on a page (See attached code). I'm new to ASP.net but it seems to me that calling a function from a class would be a very common task. But I cannot seem to figure it out and I have not been able to find a resolution in my searches.
I have multiple functions in classes that I call that appear to work, but they all seem to throw this error in the function in the class. However the exception is cleared and the correct value is returned when control returns back to the calling sub. I would not have discovered this if I had not put a try... catch block in a function.
I have tried every permutation of declaring the class as a new instance that has been suggested. They all produce the error. The error appears to be in the function GetCurrentUser1 not in the calling proc. It is cleared after on the calling proc when the function returns control. It does not seem to affect processing, "MyName" is returned from the function.
I must be doing this wrong. Does anybody call a function from a class and have working code.
This is the calling Sub
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim clsCommon1 As New clsCommon1
strCurrentUser1 = clsCommon1.GetCurrentUser1()
This is the Class
Function in clsCommon1
Public Shared Function GetCurrentUser1() As String
Dim strCurrentUser1 As String
strCurrentUser1 = "MyName"