I get this error: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class.
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod()> _
Public Shared Function ParseData() As String
Dim value as string = GetValue()
End Function
Private Function GetValue() as String
Return "halp"
End Function
End Class
I know it has something to do with the fact that the first function is shared and the second function should probably be Public as well but I don’t fully understand the reason behind it. Probably not relevant but I’m calling the web method from some javascript.
orIf it MUST be shared, then go with the first one. If you can initialize the object first, or if you’re calling it from within the same class, go with the second one.
As you’ve pointed out, the Webmethod must be Shared (static). In this case, the methods you call from the webmethod must also be shared.
EDIT:
an alternative option would be to create a separate class for “GetValue”