Same namespace, different files

R

Rico Rivera

I have two files:

FileA.vb
FileB.vb

FileA.vb contains the following sample code:

NameSpace SomeNamespace
Public Class SomeClassA
Public Shared Function MethodA() As String
...
End Function
End Class
End NameSpace

FileB.vb contains the following sample code:

NameSpace SomeNamespace
Public Class SomeClassB
Public Sub MethodB()
Dim strA As String
Error? ---> strA = SomeNamespace.SomeClassA.MethodA()
...
End Sub
End Class
End NameSpace


What I'm trying to do is call the shared method, MethodA, in
SomeClassA in FileA.vb within FileB.vb. They both have the same
namespace. FileA.vb compiles fine into a .dll but Fileb.vb has
trouble compiling saying:

error BC30456: 'MethodA' is not a member of 'SomeNamespace'

Can I do this? I would like to keep the classes in their own seperate
files.

Thanks!
 
R

Richard Myers

If they are in the same assembly you can drop the namespace reference.

SomeClassA.MethodA()

You SHOULD have different classes in different files.
Any other form of organisation, except with nested classes obviously, is not
considered best practise.

Something else you might check is in the Project settings. Make sure you
have removed the implicit default namespace from the textbox that says
"Namespace".

Otherwise the effective namespace will be a union of this implicit project
parameter and that which you have defined explicitly in the class....

i.e Possibly you cannot get a reference to MethodA because it's actually
fully qualified as

SomeNamespace.Somenamespace.SomeClassA.MethodA().

The union of the implicit and explicit namespace declarations.
So basically dont combine explicit and implicit namespacing in your
classes... standardise on one or the other....and I'd recommend explicit.

hth
Richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top