Results 1 to 5 of 5

Thread: Class library no namespace?

  1. #1

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,082

    Class library no namespace?

    OK I'm starting C# again but I have an issue.

    I create a new project and add a new class library:

    Code:
    namespace SendN
    {
        public class Class1
        {
        }
    }
    Now this is a asp.net project I have multiple VB.net class libraries that I would call by Namespace.Class , only that in here I do not see the namespace. So I just see Class1.
    Where is the namespace hiding? If I have a new function in any project I can find the VB namespace, I cannot find the C#. This cannot be so as 2 classes may conflict.
    So what I am doing wrong?
    .

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,998

    Re: Class library no namespace?

    Quote Originally Posted by sapator View Post
    OK I'm starting C# again but I have an issue.

    I create a new project and add a new class library:

    Code:
    namespace SendN
    {
        public class Class1
        {
        }
    }
    Now this is a asp.net project I have multiple VB.net class libraries that I would call by Namespace.Class , only that in here I do not see the namespace. So I just see Class1.
    Where is the namespace hiding? If I have a new function in any project I can find the VB namespace, I cannot find the C#. This cannot be so as 2 classes may conflict.
    So what I am doing wrong?
    Assuming that you have a project structure like below:

    Solution
    -> EShop (MVC Website)
    HomeController.cs
    -> SendM (Class Library)
    Class1.cs
    -> SendN (Class Library)
    Class1.cs

    In your EShop project, Add Reference to the class libraries (.dll) in the solution and in your HomeController.cs, you can simply instantiate the classes in your controller action using Namespace.Class approach.

    Code:
    public ActionResult Index()
          {
             SendM.Class1 m = new SendM.Class1();
             SendN.Class1 n = new SendN.Class1();
    
             return View();
          }
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  3. #3

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,082

    Re: Class library no namespace?

    I really don't understand why should I do that.
    I have

    MVC site -->

    --VB Class Library VB
    ----> VB Function XX

    --C# Class Library CC
    ----> C# Function YY


    Then I do:
    dim x as new VB.XX works fine
    dim y as new CC.YY there is no namespace CC to be found, it just goes to Dim y as new YY
    .

  4. #4
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    1,998

    Re: Class library no namespace?

    So you're instantiating both C# and VB.NET class libraries in a VB MVC Project. I tried replicating what you did an in fact I can both call C# and VB classes using Namespace.class

    SendMVB (VB class library)
    Code:
    Public Class ClassVB
        Function XX() As Integer
    
            Return 0
        End Function
    End Class
    SendM (C# Class library)
    Code:
    namespace SendM
    {
        public class Class1
        {
          public int YY()
          {
             return 0;
          }
        }
    }
    EShopVB (MVC)
    Code:
    Function Index() As ActionResult
    
            Dim x As New SendMVB.ClassVB
            Dim y As New SendM.Class1
    
            Dim res As Integer = x.XX()
            Dim res2 As Integer = y.YY()
    
            Return View()
        End Function
    Have your tried to clean the solution?
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

  5. #5

    Thread Starter
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,082

    Re: Class library no namespace?

    Yes it's weird I guess, maybe somehow it fall into the default namespace? I really can't tell. I will have to create a vb class and see if it works correctly.
    .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width