开发者

Can't access classes from different files in VB.NET Website

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 c开发者_JS百科ompile:

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


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


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.


You probably had a batch of errors after doing the conversion (one of them that the 'type is not defined' that you're trying to inherit from).

I recommend that you sort the errors by file name and check that there are no compile errors in the class you are trying to inherit from (as you can't inherit from a class with errors in it).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜