Reputation: 679
A little confused about class modifiers in VB.NET
In my project i have a BI layer with multiple classes. In each class i have some public methods \ functions that i expose via the public shared modifier.
However in different classes in the BI layer, i need to access methods in a different class, but the same namespace (in the BI layer) that i do not want exposed to the UI project \ layer.
I thought the Friend modifier will expose the method to classes in the same namespace, but it gives me an error saying reference to a non-shared member requires and object reference
Upvotes: 0
Views: 246
Reputation: 9024
Take the following examples.
Instance method
Friend Class Foo
Friend Sub Fubar()
'do something
End Sub
End Class
Usage:
Dim fu As New Foo
fu.Fubar()
Shared method
Friend Class Foo
Friend Shared Sub Fubar()
'do something
End Sub
End Class
Usage:
Foo.Fubar()
Upvotes: 0
Reputation: 24916
Friend modifier (internal in C#) exposes members to classes in the same assembly.
The error in your case is not related to friend modifier. From the error message it seems that you are trying to access instance (i.e. non shared) method as if it was shared method. You need an instance of the class in order to call such methods.
Code sample would be helpful, because it would help to easier tell what should be changed.
Upvotes: 1