For completeness and the sake of others looking at this thread wishing to do something similar, a sample of the AssemblyResolve handler is as follows:
- Code: Select all
static System.Reflection.Assembly AssemblyResolve(object sender, ResolveEventArgs e)
{
string jiwaApplicationPath = @"C:\Program Files (x86)\Jiwa Financials\Jiwa 7";
System.Reflection.Assembly resolvedAssembly = null;
// NOTE: sometimes e.Name is the assembly FullName, sometimes it may be a path - depending on how the assembly is attempted to be loaded - the below will handle both cases
string filename = e.Name.Split(new Char[] { ',' })[0].Replace(@"\\", @"\");
string filenameAndPath = System.IO.Path.Combine(jiwaApplicationPath, filename) + ".dll";
if (System.IO.File.Exists(filenameAndPath))
{
resolvedAssembly = System.Reflection.Assembly.LoadFrom(filenameAndPath);
}
return resolvedAssembly;
}
And somewhere in your application (before any reference to a Jiwa class), add the handler:
- Code: Select all
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;
In the above I've hard coded the path for the Jiwa assemblies location, but you probably want to make it a configuration setting, and if you want to get really fancy -
interrogate the system to find the install path of the Jiwa application (but do that once at application start and store the path - don't interrogate the system within the AssemblyResolve handler or performance will suffer).
Note that the above code does not throw an exception if it cannot locate the assembly, it simply returns a null - this is intentional as the JiwaApplication.Manager has it's own AssemblyResolve handler and will be invoked if the above returns null and should successfully resolve any plugin references (references plugins may have to other plugins, or embedded references) - it knows to look in the %ProgramData%\Jiwa Financials folder for assemblies which are compiled or placed there.