Ask a questionAsk a question
 

Answercannot declare class directly

  • Wednesday, November 04, 2009 7:31 AMmagmo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi

    I have a wpf application and a classlibrary project together with it, I have set the namespace name in the properties of the classlibrary, I have also set the namespace name in the actual vb file (in the classlibrary). Then In my xaml.vb file I can Imports xxxx.nameofclasslibrary, but I cannot declare it direct like this...

    Dim k As New name.of.my.classlibrary

    I can't figure out why, what could be wrong?

Answers

  • Friday, November 06, 2009 9:20 AMmagmo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Jialiang

    I have just discovered what caused the problem, in my solution I had a wcf service reference, this service reference was named in this way

    MM.ThenameOfmyservicereference

    And my class was named....

    MM.Cards.Pdf.TestMe

    So beacuse they both started with MM. this error ocured. This is a little suprising to me, I thought that as long as the complete name is unique I will be fine, but obviously not.

All Replies

  • Wednesday, November 04, 2009 7:49 AMHeslacher Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi magmo,

    did you add areference to your class ?
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Wednesday, November 04, 2009 8:33 AMmagmo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In my class I have a public class called Testme, if I add this to my form...

    Imports myclass.blablabla.blabla

    Then I can access the TestMe Class by this line.

    Dim n As New TestMe

    But if I remove the Imports part, I cannot do it like this...

    Dim n As New myclass.blablabla.blabla.TestMe

    Shouldn't I supposed to be able to do that?
  • Wednesday, November 04, 2009 8:40 AMHeslacher Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi again

    you need to call it:

    Dim n As New blablabla.blabla.TestMe

    without the myclass.

    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Wednesday, November 04, 2009 8:49 AMmagmo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In my assembly it look like this....

    Namespace MM.Cards.Pdf

        Public Class TestMe



    If I remove the Imports part I cannot access TestMe like this...

    Dim n As New Cards.Pdf.TestMe

    And I cannot access it like this....


    Dim n As New MM.Cards.Pdf.TestMe

    The only way I can access it is by using the Imports MM.Cards.Pdf

    and then declare it like this..

    Dim n As New TestMe



  • Wednesday, November 04, 2009 9:09 AMHeslacher Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi again,

    in pure VB.NET it works. So if you take a look inside the object browser and search for your class TestMe there you would see exactly where it is and then also how you can call it. I don`t know if this works in a wpf app.
    If you have got questions about this, just ask.
    Mark the thread as answered if the answer helps you. This helps others who have the same problem !
    C# to VB.NET: http://www.developerfusion.com/tools/convert/csharp-to-vb/
  • Wednesday, November 04, 2009 10:30 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I agree with Heslacher. Object Browser can tell you the "real" namespace of the class. You can also use .NET Reflector to see the namespace.

    Also note that VB.NET projects have a root namespace defined in the project property. The namespaces that you specify in code are appended to the root namespace. You propably missed this one.


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Friday, November 06, 2009 6:28 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hello magmo

    How are you? Do you have any progress in this issue? If you have any other questions, please feel free to post here.
    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Friday, November 06, 2009 9:20 AMmagmo Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Jialiang

    I have just discovered what caused the problem, in my solution I had a wcf service reference, this service reference was named in this way

    MM.ThenameOfmyservicereference

    And my class was named....

    MM.Cards.Pdf.TestMe

    So beacuse they both started with MM. this error ocured. This is a little suprising to me, I thought that as long as the complete name is unique I will be fine, but obviously not.
  • Monday, November 09, 2009 11:05 AMJialiang Ge [MSFT]MSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello

    I'm glad that you have discovered the problem. You are allowed to use the class by specify its complete name (complete namespace + class name). If you just use the class name, the compiler is not able to decide which class to use under both namespace.


    Regards,
    Jialiang Ge
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.