Trying this again... (Import method from DLL)
-
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! :)
-
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! :)
-
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! :)
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.
-
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! :)
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
-
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
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? :-)
-
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? :-)
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]