|
-
Apr 17th, 2002, 09:10 AM
#1
comPLETELY stumped: referencing class located within vb.net web application
Hello All,
I am in the process of learning .NET....I created a simple class in my ASP.NET web application (using VB.NET) to access my database to return a list of states to populate a user control I made to display these states. Yet when I try to Import this class and then create a new instance of it, the parser returns an error like this :
Namespace or type 'Class1' for the Imports 'WebApplication1.MyClassNameSpace.Class1' cannot be found
the program line on which this error occurs is :
Imports WebApplication1.MyClassNameSpace.Class1
this line is at the very top of the code-behind file for my aspx page, AND I can drag & drop that line from the Class View which tells me the project "knows" about my class, yet somehow can't find it at runtime...
i've created smaller web projects with the sole intention of just getting a class defined by myself to import into another .vb file and simply CAN'T get it to work, and neither can my co-workers....also, i have successfully created this class in a separate project, compiled it, and referenced it within this web app, so i am left with thinking that you must do something special to a class you define within a web application in order to make it accessible to other classes in the same web app.
does anyone have any insight into this problem??
Thank you very much for your time,
Kenton Taylor
-
Apr 17th, 2002, 09:14 AM
#2
is the class wrapped in said namespaces
???
Code:
Namespace WebApplication1
Namespace MyClassNameSpace
really though, I dont think you need the namespaces if you are using a straight forward class..just reference the class as is if it is added as part of the application
Dim A As New Class1
you would want to use the namespace if the class in a seperate dll.
-
Apr 17th, 2002, 09:17 AM
#3
I haven't got much experience with .NET (yet), but this is what I read somewhere:
If the class is in a seperate dll, the dll must be placed in the same directory, or a subdirectory of your web application, or the dll must be installed in the global assembly cache.
-
Apr 17th, 2002, 09:22 AM
#4
reply to cander
the namespaces don't make any difference...
here's my code:
Class1.vb located within WebApplication1
Public Class Class1
Public MyMember As String
Sub New()
MyMember = "constructor worked"
End Sub
End Class
WebForm2.aspx.vb located within WebApplication1
Imports WebApplication1.Class1
Public Class WebForm2
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim ThisWontWork As Class1
ThisWontWork = New Class1()
End Sub
End Class
the exact error msg is:
Compiler Error Message: BC30466: Namespace or type 'Class1' for the Imports 'WebApplication1.Class1' cannot be found.
Line 2: Imports WebApplication1.Class1
can anyone else get this simple example to work?? Just a simple class within a web application, where an aspx.vb file can import and dim an instance of that class. completely stumped.
-Kenton
-
Apr 17th, 2002, 09:39 AM
#5
You shouldn't have to make any references as the class is really part of your project. It's very similar to how you could create a class in VB6 and all references are "created" when you add that module to your project. If you created a dll, you would have to reference it, but if it's your standard run of the mill class, no referencing or importing is necessary.
-
Apr 18th, 2002, 06:19 AM
#6
Junior Member
Remove the class reference from the end of the imports line.
It is trying to find Class1 in WebApplication.Class1
The imports line should be
imports WebApplication
hope this helps
cheers
Simon
-
Apr 18th, 2002, 07:50 AM
#7
I figured it out
so for any who want to know - the solution to this problem is this :
in order to reference a class that exists within a .net web application at runtime, you first have to build the solution before running an aspx or aspx.vb file, otherwise it will come back type not found, even though the project is aware of that class at design time.
case closed.
kenton
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|