Hello,
I have been stuck on this for some time. What I am trying to do is load several DLL's from subfolders in my application.
I have looked at many articles including:
How the Runtime Locates Assemblies
AppDomain.AssemblyResolve Event Tips - CodeProject
Loading Assemblies from Anywhere into a New AppDomain - CodeProject
and finally,
The whole concept seems confusing to me however, as the are many ways to do this based on how your program is set up. So, let me explain.
Firstly, I am using an Application Context, with a constructor to load everything. My Sub Main looks like this:
Public NotInheritable Class SubMain Public Shared Sub Main() 'First check for other running instances, and exit the program if any are found For Each runningProcess As Process In Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName) If Not runningProcess.Id = Process.GetCurrentProcess.Id Then If MessageBox.Show("Another instance of this program is already running." & vbCrLf & vbCrLf & "Would you like to close it, and start this instance instead?", Reflection.AssemblyName.GetAssemblyName(Application.ExecutablePath).Name & ": Notice", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) = DialogResult.No Then Application.Exit() Exit Sub Else runningProcess.Kill() End If End If Next Application.EnableVisualStyles() Application.Run(New AppContext) End Sub End Class
From what I read, this whole process needs to be done before the Sub Main is even called, according to:
AppDomain.AssemblyResolve Event Tips - CodeProject
Secondly, my program is designed to be entirely portable. From what I understand, GAC only affects one computer.
I have messsed with things like AppDomainSetup, Assembly.LoadFrom, and even AssemblyResolve.
AssemblyResolve seems like the right way to go for me, since if there is an error in loading a reference, I can simply point it to the right one in the subfolder. Unfortunately, this is the only method I seem to fully grasp. However when I attempt this method anytime after Sub Main, I get a "file not found" error, just like AppDomain.AssemblyResolve Event Tips - CodeProject said I would.
I am writing this in Visual Basic, and know just somewhat of C#; but not enough to fully understand the code. Most of the examples I find are in C#, and so are a bit more difficult for me to understand.
So I suppose what I'm asking is: How do I load DLL's from subfolders, in a program that has an application context, and is designed to be portable?
Thanks,
- Jake M.