Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Namespace conflicts with page class - name resolution difference in compiler

Reply
Thread Tools

Namespace conflicts with page class - name resolution difference in compiler

 
 
Shadow Lynx
Guest
Posts: n/a
 
      02-03-2006
If this is not the most appropriate group for this question, please let
me know.

I noticed an odd priority difference in resolving names in VS 2005 (VWD
Express) vs. the .NET 2.0 compiler (the one accessed from within VS).

Let me give an example to clarify things.

In a test solution, I created two web form pages with codebehinds and a
class in the App_Code folder:
App_Code\Simple.vb
Default.aspx (and *.vb)
Level2.aspx (and *.vb)

App_Code\Simple.vb:
Namespace Level1.Level2
Public Class Simple
Public ReadOnly Property Message() As String
Get
Return "Hello"
End Get
End Property
End Class
End Namespace

You may have noticed the Level1.Level2 Namespace...
Level2.aspx and *.vb contain default content - the .vb starts with
Class Level2

Default.aspx.vb: (the .aspx file contains default content)
Imports System.Data
Imports System.Data.SqlClient
Imports Level1
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
--> Dim TestInstance As New Level2.Simple
Response.Write(TestInstance.Message)
End Sub
End Class

When writing the code, there is no error flag on the line with the
arrow. VS recognizes Level2.Simple properly (or maybe it's not proper)
because of the Imports Level1 line.

If I attempt to build the site, however, I get the error (due to the
line with the arrow):
C:\Inetpub\wwwroot\ASPX2_Test\Default.aspx.vb(9,0) : error BC30002: Type
'Level2.Simple' is not defined.

Of course, the following replacement line makes the build process
happy:
Dim TestInstance As New Level1.Level2.Simple

Which one is in error - the VS inline error checker or the build
process itself? While I prefer the VS priority, the Build priority may
be correct because the page Level2.aspx.vb contains a Level2 class
which is actually in the same namespace (none) as the Default.aspx.vb
page.

 
Reply With Quote
 
 
 
 
Christopher Reed
Guest
Posts: n/a
 
      02-04-2006
Your namespace is Level1.Level2, so you need:

Imports Level1.Level2

Then you'll have

Dim TestInstance As New Simple

Keep in mind that when using the Website model in VWD Express that if you
leave off the namespaces in all files including the class files in the
App_Code directory, then a default namespace is created for you and you
won't need to import a namespace for your Simple class.
--
Christopher A. Reed
"The oxen are slow, but the earth is patient."

"Shadow Lynx" <> wrote in message
news: oups.com...
> If this is not the most appropriate group for this question, please let
> me know.
>
> I noticed an odd priority difference in resolving names in VS 2005 (VWD
> Express) vs. the .NET 2.0 compiler (the one accessed from within VS).
>
> Let me give an example to clarify things.
>
> In a test solution, I created two web form pages with codebehinds and a
> class in the App_Code folder:
> App_Code\Simple.vb
> Default.aspx (and *.vb)
> Level2.aspx (and *.vb)
>
> App_Code\Simple.vb:
> Namespace Level1.Level2
> Public Class Simple
> Public ReadOnly Property Message() As String
> Get
> Return "Hello"
> End Get
> End Property
> End Class
> End Namespace
>
> You may have noticed the Level1.Level2 Namespace...
> Level2.aspx and *.vb contain default content - the .vb starts with
> Class Level2
>
> Default.aspx.vb: (the .aspx file contains default content)
> Imports System.Data
> Imports System.Data.SqlClient
> Imports Level1
> Partial Class _Default
> Inherits System.Web.UI.Page
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As
> System.EventArgs) Handles Me.Load
> --> Dim TestInstance As New Level2.Simple
> Response.Write(TestInstance.Message)
> End Sub
> End Class
>
> When writing the code, there is no error flag on the line with the
> arrow. VS recognizes Level2.Simple properly (or maybe it's not proper)
> because of the Imports Level1 line.
>
> If I attempt to build the site, however, I get the error (due to the
> line with the arrow):
> C:\Inetpub\wwwroot\ASPX2_Test\Default.aspx.vb(9,0) : error BC30002: Type
> 'Level2.Simple' is not defined.
>
> Of course, the following replacement line makes the build process
> happy:
> Dim TestInstance As New Level1.Level2.Simple
>
> Which one is in error - the VS inline error checker or the build
> process itself? While I prefer the VS priority, the Build priority may
> be correct because the page Level2.aspx.vb contains a Level2 class
> which is actually in the same namespace (none) as the Default.aspx.vb
> page.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro function conflicts namespace function? Immortal Nephi C++ 3 07-10-2010 01:23 PM
c# namespace conflicts Microsoft Newsserver ASP .Net 1 01-17-2008 01:05 AM
Compiler Error Message: CS0246: The type or namespace name 'AjaxPr =?Utf-8?B?V2ViRGV2Mg==?= ASP .Net 0 08-24-2006 10:17 AM
ERROR CS0234: The type or namespace name 'DataAccessHelper' does not exist in the namespace 'BCC' (are you missing an assembly reference?) li.eddie@gmail.com ASP .Net 0 01-06-2006 11:31 AM
derived / base class name conflicts christopherlmarshall@yahoo.com Python 11 11-16-2005 05:47 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57