views:

50

answers:

2

I've inherited a VB.NET website and it won't compile because the class1 in the file class1.vb refers to class2 in a file called class2.vb. I get the following error when trying to compile:

Type Class2 is not defined.

When I look in the object browser the classes are listed separately (i.e. not all grouped under the same namespace) and appear as:

Public Class Class 
    Inherits System.Object
     Member of C:\...\mywebsite\

Code:

Public Class Class1
    Public Enum CountType
        Morning = 0
    End Enum
    Public Sub LogError(ByVal exp As Exception, ByVal err As ErrObject, _ 
                        ByVal sRoutine As String, _
                        Optional ByVal sMod As String = "")

    End Sub

End Class

Class2.vb

Public Class Class2

    Public Enum CountTypes
        Morning = 0
        Noon = 1
        Evening = 2
        Night = 3
        Other = 4
    End Enum

    Public Sub LogErrors(ByVal exp As Exception, _ 
                         ByVal err As ErrObject, _
                         ByVal sRoutine As String, _ 
                         Optional ByVal sMod As String = "")

    Dim cl As Class1   ' error here

    End Sub
End Class
A: 

If it's within the same project but in a different namespace make sure there is a using directive at the top to import the namespace you want access to

Josh Smeaton
There is no namespaces directly on the classes, I guess they use the project default, it is like this:Option Explicit OnOption Strict OnImports System.DataImports System.Data.SqlClientImports System.CollectionsPublic Class DataAccess...
I wrapped both files within a namespace statement and now in the object browser all the classes from both files appear grouped under the same namespace, but I still can't refer to a class from one file from the other file:Namespace myspace Public Class Class2
As an edit to your original post, can you paste the class definitions for each? Everything from the top of the file, to the public class Class1/2 {}. The methods within each are unimportant.
Josh Smeaton
I have no idea what the problem was with the project in Visual Studio. I ended up reverting the files in the folder to an earler visual studio project version of the project, letting VS convert to 2008, then getting latest from tfs and it works.
A: 

I have no idea what the problem was with the project in Visual Studio. I ended up reverting the files in the folder to an earler visual studio project version of the project, letting VS convert to 2008, then getting latest from tfs and it works.