Load assembly dynamically and call methods
-
Hi, I am working with a C# project containing different assemblies. One of the assemblies A is used by other assemblies, added as a reference link. Now we want to load this assembly dynamically at runtime instead and calling its methods. There is no problem loading assembly A dynamically Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(assemblyName)); I can call methods in assembly A throught MethodInfo method = Type.GetMethod("MethodXX"); method.Invoke(null, null); Now to my question. Do I have to call all methods in assembly A with Invoke(...) or can I just create a interface and call methods with MethodXX(....)? Regards Olof
-
Hi, I am working with a C# project containing different assemblies. One of the assemblies A is used by other assemblies, added as a reference link. Now we want to load this assembly dynamically at runtime instead and calling its methods. There is no problem loading assembly A dynamically Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(assemblyName)); I can call methods in assembly A throught MethodInfo method = Type.GetMethod("MethodXX"); method.Invoke(null, null); Now to my question. Do I have to call all methods in assembly A with Invoke(...) or can I just create a interface and call methods with MethodXX(....)? Regards Olof
If you can define an interface that is non-dynamic and part of your EXE (or a non-dynamically linked DLL), and the dynamically loaded assembly holds a type implementing that interface, then yes that is the easy way out to use the dynamic type. A non-dynamic base class could work well too. :)
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
Hi, I am working with a C# project containing different assemblies. One of the assemblies A is used by other assemblies, added as a reference link. Now we want to load this assembly dynamically at runtime instead and calling its methods. There is no problem loading assembly A dynamically Assembly assembly = Assembly.LoadFrom(Path.GetFullPath(assemblyName)); I can call methods in assembly A throught MethodInfo method = Type.GetMethod("MethodXX"); method.Invoke(null, null); Now to my question. Do I have to call all methods in assembly A with Invoke(...) or can I just create a interface and call methods with MethodXX(....)? Regards Olof
why you create interface??? you no need tthe redefinition of methods another time ( exist in assembly!!) you need juste to invoke method from assembly A. :)