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. C#
  4. Trying this again... (Import method from DLL)

Trying this again... (Import method from DLL)

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 5 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.
  • A Offline
    A Offline
    Azad Giordano Ratzki
    wrote on last edited by
    #1

    Is it possible to import a method from a DLL and run it as if it were in the same namespace? The problem I am running into is this (Application = CA2, DLL = AnyDLL) : 1. CA2 references AnyDLL and invokes method in AnyDLL. 2. Method in AnyDLL tries to use GetType to get a class in CA2. 3. Exception happens because the DLL can't see the class in CA2. Is there any way around this? I would think many different times a person would want to use a method in a DLL as if the code for the method was right there and not in the DLL? Any help is much appreaciated! :)

    G L N 3 Replies Last reply
    0
    • A Azad Giordano Ratzki

      Is it possible to import a method from a DLL and run it as if it were in the same namespace? The problem I am running into is this (Application = CA2, DLL = AnyDLL) : 1. CA2 references AnyDLL and invokes method in AnyDLL. 2. Method in AnyDLL tries to use GetType to get a class in CA2. 3. Exception happens because the DLL can't see the class in CA2. Is there any way around this? I would think many different times a person would want to use a method in a DLL as if the code for the method was right there and not in the DLL? Any help is much appreaciated! :)

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Don't repost the same question so close after the first.

      --- single minded; short sighted; long gone;

      1 Reply Last reply
      0
      • A Azad Giordano Ratzki

        Is it possible to import a method from a DLL and run it as if it were in the same namespace? The problem I am running into is this (Application = CA2, DLL = AnyDLL) : 1. CA2 references AnyDLL and invokes method in AnyDLL. 2. Method in AnyDLL tries to use GetType to get a class in CA2. 3. Exception happens because the DLL can't see the class in CA2. Is there any way around this? I would think many different times a person would want to use a method in a DLL as if the code for the method was right there and not in the DLL? Any help is much appreaciated! :)

        L Offline
        L Offline
        Leslie Sanford
        wrote on last edited by
        #3

        Taicho2k wrote:

        1. CA2 references AnyDLL and invokes method in AnyDLL. 2. Method in AnyDLL tries to use GetType to get a class in CA2. 3. Exception happens because the DLL can't see the class in CA2. Is there any way around this? I would think many different times a person would want to use a method in a DLL as if the code for the method was right there and not in the DLL?

        Yeah, does sound like a circular reference. I try to avoid circular references like the plague. My advice would be to factor out the class in your executable to a second assembly. Then the first assembly can reference the second one to access the class. The executable can reference both assemblies to use the classes/methods it needs. This breaks the circular reference and makes things easier to manage and understand.

        1 Reply Last reply
        0
        • A Azad Giordano Ratzki

          Is it possible to import a method from a DLL and run it as if it were in the same namespace? The problem I am running into is this (Application = CA2, DLL = AnyDLL) : 1. CA2 references AnyDLL and invokes method in AnyDLL. 2. Method in AnyDLL tries to use GetType to get a class in CA2. 3. Exception happens because the DLL can't see the class in CA2. Is there any way around this? I would think many different times a person would want to use a method in a DLL as if the code for the method was right there and not in the DLL? Any help is much appreaciated! :)

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          CA2 references AnyDLL and AnyDLL references CA2? What you have is a circle reference and not a very good design. You either need to redesign or do a better job of explaining what you are trying to do, or want to do.


          only two letters away from being an asset

          A 1 Reply Last reply
          0
          • N Not Active

            CA2 references AnyDLL and AnyDLL references CA2? What you have is a circle reference and not a very good design. You either need to redesign or do a better job of explaining what you are trying to do, or want to do.


            only two letters away from being an asset

            A Offline
            A Offline
            Azad Giordano Ratzki
            wrote on last edited by
            #5

            Thanks for the replies everyone, I'm probably not explaining myself too well...the method I am trying to use from my dll is a method that uses System.Reflection to be able to run any other method by using a string so when I say that the method in AnyDLL is referencing a method in my application pretend that the method could be referencing any method in any other application...essentially I am just trying to get the method in the DLL to run as if it were running directly in the application and not contained in some DLL...is that even possible? I was experimenting w/ DllImport and now I've begun playing around w/ Assembly.LoadFrom("dllname") thanks to an earlier suggestion... any more ideas? :-)

            L 1 Reply Last reply
            0
            • A Azad Giordano Ratzki

              Thanks for the replies everyone, I'm probably not explaining myself too well...the method I am trying to use from my dll is a method that uses System.Reflection to be able to run any other method by using a string so when I say that the method in AnyDLL is referencing a method in my application pretend that the method could be referencing any method in any other application...essentially I am just trying to get the method in the DLL to run as if it were running directly in the application and not contained in some DLL...is that even possible? I was experimenting w/ DllImport and now I've begun playing around w/ Assembly.LoadFrom("dllname") thanks to an earlier suggestion... any more ideas? :-)

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #6

              Hi, some info, not a full solution tho: - you need DllImport to call unmanaged (i.e. native) code (that resides in a dll) from managed code (say C# that resides in an exe or another dll), and nowhere else; if everything is managed, then NO DllImport. - you can distribute managed code over as many DLL files you want, it does not really matter; if it needs to bind at run-time (as with reflection), then your code must find the right DLL; finding the class and member/method inside it is independent of the EXE/DLL where they reside. SO my suggestion is: first try to have an EXE perform reflection on itself; only when you get that working, move the reflecting code to another DLL and make it work again. :)

              Luc Pattyn [My Articles] [Forum Guidelines]

              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