 |
 |

01-26-2007, 11:15 AM
|
 |
Hell's Angel
Retired Moderator * Guru *
|
|
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
|
|
Class Library Namespace is hidden
|
Hi all,
I'm having a bizarre problem with namespaces. The setup is quite simple. I have a class library with some common functions which lives is a 2nd tier namespace.
This library is used in a program that defines a 2nd tier namespace that lives in the 1st tier namespace used in the library.
Here's the class library code:
Code:
Namespace PSquared
Public NotInheritable Class Common
Public Shared Function CnvArrayToList(Of T)(ByVal arr() As T) As List(Of T)
Return CnvArrayToList(arr, 0, arr.Length)
End Function
Public Shared Function CnvArrayToList(Of T)(ByVal arr() As T, ByVal Start As Integer) As List(Of T)
Return CnvArrayToList(arr, Start, arr.Length - Start)
End Function
Public Shared Function CnvArrayToList(Of T)(ByVal arr() As T, ByVal Start As Integer, ByVal Length As Integer) As List(Of T)
Dim List As New List(Of T)
Dim StartIndex As Integer = Range(Of Integer)(Start, arr.GetLowerBound(0), arr.GetUpperBound(0))
Dim EndIndex As Integer = Range(Of Integer)(Start + Length - 1, arr.GetLowerBound(0), arr.GetUpperBound(0))
For i As Integer = StartIndex To EndIndex
List.Add(arr(i))
Next
Return List
End Function
End Class
End Namespace
And the main project:
Code:
Namespace PSquared.Talkback
Public Class CTalkbackService
Inherits System.ServiceProcess.ServiceBase
Protected Overrides Sub OnStart(ByVal args() As String)
' Add code here to start your service. This method should set things
' in motion so your service can do its work.
End Sub
Protected Overrides Sub OnStop()
' Add code here to perform any tear-down necessary to stop your service.
End Sub
End Class
End Namespace
When I rename the main app namespace to something else the PSquared.Common class is visible. However, with the PSquared.Talkback namespace in place the stuff from the library is unavailable.
Oddly, if I remove the namespace statement and use the project root namespace setting instead then it works.
What am I missing here?
|
__________________
A wise one man once said "what you talking about dog breath"
|

01-28-2007, 03:37 PM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
Looks like the PSquared.Talkback name overrides the existing PSquared and it only expects .Talkback to be a member.
Maybe you should try Importing PSquared into the PSquared.Talkback namespace (I don't know if it will work though).
My initial thought is that your PSquared.Talkback namespace should be in the PSquared namespace.
|
|

02-02-2007, 05:00 AM
|
 |
Hell's Angel
Retired Moderator * Guru *
|
|
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
|
|
|
Obviously having all of the PSquared namespace code in one file would make it work, but if my understanding of how namespaces are supposed to work, doesn't that defeat the point.
I thought it was supposed to allow this sort of namespace extension, effectively merging code from different files into a namespace.
The odd thing is that using the default namespace instead of an explicit one works fine. I had thought that the default namespace was simply a shortcut to avoid having to put namespace statements throughout your code. Obviously it's a little complex than that.
|
__________________
A wise one man once said "what you talking about dog breath"
|

02-02-2007, 10:23 AM
|
|
Ultimate Contributor
Retired Leader * Expert *
|
|
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
|
|
|
In VB, explicitly defined namespaces live under the root namespace defined in the project file.
For example, if your library's name is "CommonLib" then the default root namespace assigned by Visual Studio is "CommonLib" - you would need to change the root namespace to "PSquared" and define your "Common" class in the root namespace. Your "main application" project should then have the root namespace "PSquared.Talkback".
See the attached solution for an example.
|
|

02-09-2007, 03:45 AM
|
 |
Hell's Angel
Retired Moderator * Guru *
|
|
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394
|
|
|
ok, I get it. So there's no way to break out of the root namespace using the Namespace command in code.
|
__________________
A wise one man once said "what you talking about dog breath"
|

02-09-2007, 03:48 AM
|
|
Ultimate Contributor
Retired Leader * Expert *
|
|
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
|
|
|
In VB2005 you can clear the root namespace for the project, but this means you'll need to explicitly define each namespace you want to use. I'm not sure if VB2003 has the same behavior.
|
Last edited by shaul_ahuva; 02-09-2007 at 03:56 AM.
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|