[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12660
  • Last Modified:

Compiler Error Message:BC30002: Type 'MyClass' is not defined.

Compiler Error Message:BC30002: Type 'MyClass' is not defined.

I get The following Error Message: BC30002: Type 'MyClass' is not defined. Basically vb.net doesn't recognize my Class that i have made. i try to make the project as simple as possible to see if i can get around this problem but unfortunately i can't.
My project is made up of two simple files a web page called' DEFAULT.ASPX'  and a custom class called 'MyClass.vb'.
The aspx web page is made up of two components a grid and a button as shown underneath:

<asp:Button ID="Button1" runat="server" Text="Button"/>
<asp:DataGrid ID="Datagrid1" runat="server">

The code behind of the default.aspx page has the following syntax:

Imports MyClass

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myDAL  As MyClass= New MyClass
        Datagrid1.DataSource = myDAL.GetAllCustomersDAL

    End Sub
End Class

the  MyClass.vb file is located in the App_Data folder and  has the following syntax:

Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Data.OleDb

Public Class MyClass
    Inherits System.Web.UI.Page
    Public DataBaseLocation As String = "C:\northwind.mdb"
    Public ConnString As String = "Provider=Microsoft.jet.oledb.4.0;Data Source=" + DataBaseLocation + ""

    Public Function GetAllCustomersDAL() As DataSet

        Dim Dataset1 As DataSet = New DataSet

        Dim SQLCommand As String
        Dim MyConnection As OleDbConnection = New OleDbConnection
        MyConnection.ConnectionString = ConnString
        SQLCommand = "SELECT * FROM customers"
        Dim dataAdapter1 As OleDbDataAdapter = New OleDbDataAdapter(SQLCommand, MyConnection)
        dataAdapter1.Fill(Dataset1, "customers")

        Return Dataset1

    End Function
End Class

I also opened the VS 2005 command prompt and navigated to the appropriate folder and entered the following command:
vbc /r:System.dll,system.web.dll,microsoft.visualbasic.dll /t:library /out:MyClass.dll MyClass.vb
This creates the MyClass.dll in the same directory where the MyClass.vb is located (App_Code).
After this step i add reference to the file by going to Add References, this adds the 'MyClass.dll' file to the 'BIN' directory of the project. I would like to point out that the web application runs fine when i am in the VB.NET environment i.e (http://localhost:1563//myProject/default.aspx) but I get the ERROR when i run the web application off the web server on my computer i.e (http://www.wiredbrain123.com/default.aspx).  Any help is appreciated, i am very desperate since i have tried everything i know and i have had this problem for the past month now with no solution.
thanks in advance,
  • 3
  • 3
1 Solution
where is your MyClass.vb file located, App_Data or App_Code (You mentioned it being in both places), It needs to be in App_Code.

You also don't need to use vbc with a web project, I'd get rid of any .dll's you may have created with this class in it.
mmouzakitisAuthor Commented:
The MyClass.vb is located in the  App_Code only not the App_Data. That was a typo error.   I have also tried running the web application without creating any dlls but without any luck!
Try taking away the "Imports MyClass" at the top of your aspx.vb file, I know you do not need this.

Also, if this doesn't fix it, can you post the top few lines of your .aspx file (The ones that start with <%@...)

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

mmouzakitisAuthor Commented:
I took away the 'Imports MyClass' at the top of the aspx.vb file. it works in the VB.NET environment but doesn't work on my web server.
The following code is from the aspx file:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
I'd clear everything out of your /bin folder, something is messed up beyond what you've given me here.  I see no reason why this should fail given what you've given me, unless you haven't set the main folder of the application as an application in IIS, and asp.net is looking at another app_code folder and ignoring the one you've made.  This is the only thing I could think that would make it work in VS 2005 but not at runtime.
mmouzakitisAuthor Commented:
THANKS A LOT that was the solution. i hadn't configured IIS properly  and specifically the 'application name' THANKS AGAIN

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now