locked
class names and namespace behaviour RRS feed

  • Question

  • User1146984159 posted

    This is something that I'm not sure if it's a problem or something I have configured wrong. Just thinking on it is making my head hurt!!

    So here goes. What I'm doing...

     

    1. create a blank VS2010 web project called "MySite" targeted at 4.0

    2. create a new class object, calling it "class1.vb" (cause it's so unique!!)

    3. change default code to read as such...

    Namespace MySite
        Public Class Functions
            Public Shared Function WhatIsTodaysDate() As String
                Return Date.Now.ToLongDateString
            End Function
        End Class
    End Namespace
    


    4. create a new webform and drop a label control on it.

    In the page_load event, I want to set the label to equal the value of Function WhatIsTodaysDate. Simple enough, but now comes the part that escapse me.

    I can do this...

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Label1.Text = MySite.Functions.WhatIsTodaysDate()
    End Sub
    

    but if I want to shorten my code, and call the function using an "Imports" tag i have to do this...

    Imports MySite.MySite.Functions
    
    Public Class WebForm1
        Inherits System.Web.UI.Page
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Label1.Text = WhatIsTodaysDate()
        End Sub
    
    End Class


    Why is VS asking me to call the namespace twice if I use the "Imports" directive????

    I'm sure this has got something to do with VS2010 and the 4.0 framework.

     



     

    Sunday, September 5, 2010 2:46 PM

Answers

  • User2138254679 posted

    Hi


    To solve your problem right click on project and goto properties, in Application tab there is namespace with MySite.MySite change it to MySite and you have solution.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 5, 2010 3:33 PM

All replies

  • User2138254679 posted

    Hi


    To solve your problem right click on project and goto properties, in Application tab there is namespace with MySite.MySite change it to MySite and you have solution.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, September 5, 2010 3:33 PM
  • User1146984159 posted

    The Assembly Name says "MySite" and the Root namespace is also "MySite". Removing the "Root namespace" entry gives me the behavior I'm looking for.

    I've never noticed this before in VS. Doesn't this seem like abnormal behaviour?

     

    Sunday, September 5, 2010 4:20 PM