Reputation: 49
I have 2 versions of same dlls. Say named, Test.dll. I want to call 2 dlls from my console application.
I tried to use Extern alias. But it is calling new dll. I am calling these 2 dlls from my DAL class.
Any help would be appreciated.
Thanks,
Upvotes: 1
Views: 89
Reputation: 63065
you can use Assembly.LoadFile or using alias
Upvotes: 0
Reputation: 33501
This is not the default way of how you do things in .net, therefore coding will not be easy in such a manner. As @Johnathon Reinhart says in his answer, you will have to use Assembly.Load
(by passing the fully qualified assembly name to the function).
Like this:
Assembly asmOld = Assembly.Load("MyAssembl, Version=1.0.0.1, Culture=neutral, PublicKeyToken=ab1234567defabc1");
Assembly asmNew = Assembly.Load("MyAssembl, Version=2.0.0.1, Culture=neutral, PublicKeyToken=ab1234567defabc1")
Moreover, you will have to keep reference to both assemblies and then use Assembly.CreateInstance
to create instances of the types you need. After that, you will have to call members using reflection (something like this). Like this:
Ojbect objOld = asmOld.CreateInstance("MyApp.Namespace.Classname");
Ojbect objNew = asmNew.CreateInstance("MyApp.Namespace.Classname");
objOld.GetType().InvokeMember("TestMethod", BindingFlags.InvokeMethod,null,obj,null);
objNew.GetType().InvokeMember("TestMethod", BindingFlags.InvokeMethod,null,obj,null);
To improve your code writing, you could use the LateCall
from Microsoft.VisualBasic.CompilerServices
to work with your objects. There is a nice wrapper for that by Andy Adinborough - http://andy.edinborough.org/Use-Late-Binding-in-C-Now-without-NET-4-0
Upvotes: 1
Reputation: 137398
I'm assuming that these DLLs are .NET assemblies, and not just standard C DLLs.
If so, I think you can specifically load the assembly with the static Assembly.LoadFrom(string assemblyFile)
. Then I think you can get a module from that assembly with Assembly.GetModule()
.
Upvotes: 0