Another way to use the code above is to create dynamic "dynamic linking", to download dlls and embed them during runtime!
How to do this:
1. Add a project reference to a COM object, but
DO NOT include the DLL in the executable folder
2. Do not call any of the functions from the COM ref above, until after you complete the following steps:
3. Download a byte array from a website during runtime, this is your recent most updated DLL COM file, save the dll into: byte[] bytes (for the example purpose).
4. Add the following lines to your project:
System.Reflection.Assembly myCOM = System.Reflection.Assembly.Load(bytes);
System.ResolveEventHandler CurrentDomain_AssemblyResolve_ResolveEventHandler;
CurrentDomain_AssemblyResolve_ResolveEventHandler = new System.ResolveEventHandler(CurrentDomain_AssemblyResolve);
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve_ResolveEventHandler;
Add the function to catch the 'DLL not found' event:
public System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs arg)
{
if (arg.Name.Contains("NAME_OF_THE_COM_YOU_ADDED"))
{
return myCOM;
}
}
5. Now call the function you need from the COM, and the dynamically downloaded DLL will be attached during runtime ^^
And this is another example of how to use the code above :)