Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. GetType on a Referenced Assemble without hardcoding assembly loadfrom values

GetType on a Referenced Assemble without hardcoding assembly loadfrom values

Scheduled Pinned Locked Moved Visual Basic
helpquestion
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MartyK2007
    wrote on last edited by
    #1

    Hello, I have a problem : I have a class Library (FooClasses) which has a refence to a second set of classes (Foo2Classes) In Foo2Classes is a class (Foo3) I have the following code Imports System.Reflection Imports Foo2Classes Public Class FooClass Protected Sub SomeSub() Dim T as Type T = Type.GetType("Foo2Classes.Foo3") I have also tried T = Type.GetType("FooClasses.Foo2Classes.Foo3") End Sub End Class The T cant be found by reflection so I am assuming I must load the Foo2Classes assembly first. If this is the case how can I load the assembly without using a hardcoded path in a loadfrom. What I want to be able to do is to use the fact that it has been referenced in my FooClasses. Can you get the path from the assembly reference , rather than hardcoding it OR putting in a partially qualified pathname ie "/subdir/Foo2Classes.dll" Thanks Martin

    life is a bowl of cherries go on take a byte

    D 1 Reply Last reply
    0
    • M MartyK2007

      Hello, I have a problem : I have a class Library (FooClasses) which has a refence to a second set of classes (Foo2Classes) In Foo2Classes is a class (Foo3) I have the following code Imports System.Reflection Imports Foo2Classes Public Class FooClass Protected Sub SomeSub() Dim T as Type T = Type.GetType("Foo2Classes.Foo3") I have also tried T = Type.GetType("FooClasses.Foo2Classes.Foo3") End Sub End Class The T cant be found by reflection so I am assuming I must load the Foo2Classes assembly first. If this is the case how can I load the assembly without using a hardcoded path in a loadfrom. What I want to be able to do is to use the fact that it has been referenced in my FooClasses. Can you get the path from the assembly reference , rather than hardcoding it OR putting in a partially qualified pathname ie "/subdir/Foo2Classes.dll" Thanks Martin

      life is a bowl of cherries go on take a byte

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      MartyK2007 wrote:

      If this is the case how can I load the assembly without using a hardcoded path in a loadfrom.

      Use the Path class to build the fully qualified path to the assembly.

      Dim fullPath As String = Path.Combine(Application.StartupPath, "myAssembly.dll")
      

      MartyK2007 wrote:

      Can you get the path from the assembly reference

      The reference only exists to keep the compiler happy. They don't exist at runtime.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      M 1 Reply Last reply
      0
      • D Dave Kreskowiak

        MartyK2007 wrote:

        If this is the case how can I load the assembly without using a hardcoded path in a loadfrom.

        Use the Path class to build the fully qualified path to the assembly.

        Dim fullPath As String = Path.Combine(Application.StartupPath, "myAssembly.dll")
        

        MartyK2007 wrote:

        Can you get the path from the assembly reference

        The reference only exists to keep the compiler happy. They don't exist at runtime.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        M Offline
        M Offline
        MartyK2007
        wrote on last edited by
        #3

        Hello, yes your assuming the assembly is in the startup path - is that a valid assumpton? I may have a solution though I think I can get the fully qualified name of the assembly from the current executing assemblies refernce collection. This value doest have a path in it at all. from there I can issue am assembly load using the fully qualified Name and it seems to get it. I am testing to see if this happens in all cases thanks Martin

        life is a bowl of cherries go on take a byte

        D 1 Reply Last reply
        0
        • M MartyK2007

          Hello, yes your assuming the assembly is in the startup path - is that a valid assumpton? I may have a solution though I think I can get the fully qualified name of the assembly from the current executing assemblies refernce collection. This value doest have a path in it at all. from there I can issue am assembly load using the fully qualified Name and it seems to get it. I am testing to see if this happens in all cases thanks Martin

          life is a bowl of cherries go on take a byte

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          MartyK2007 wrote:

          yes your assuming the assembly is in the startup path - is that a valid assumpton?

          No, it's not, and it wasn't meant to be an assumption. I gave you an example of building a path from a well-known starting point.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          M 1 Reply Last reply
          0
          • D Dave Kreskowiak

            MartyK2007 wrote:

            yes your assuming the assembly is in the startup path - is that a valid assumpton?

            No, it's not, and it wasn't meant to be an assumption. I gave you an example of building a path from a well-known starting point.

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            M Offline
            M Offline
            MartyK2007
            wrote on last edited by
            #5

            ok no offense meant. The issue with that is that your dll's have to be below your app.startup which in my case may not be relevent I think the fully qualified name though has legs - still testing thanks for your help Martin

            life is a bowl of cherries go on take a byte

            D 1 Reply Last reply
            0
            • M MartyK2007

              ok no offense meant. The issue with that is that your dll's have to be below your app.startup which in my case may not be relevent I think the fully qualified name though has legs - still testing thanks for your help Martin

              life is a bowl of cherries go on take a byte

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              There's more than one place to put .DLL's. GetFolderPath[^] and the Environment.SpecialFolder Enumeration[^]

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups