|
-
April 30th, 2010, 09:31 AM
#1
Linking an executable to a loaded DLL
Hello,
I have an application that is being deployed on an intranet. The main executable is a windows form that references several DLLs, and these DLLs need to be updated from time to time. Users are using the application by referencing the executable on a shared drive. The problem is that once a user runs the application, the executable and DLLs are locked by the user and therefore cannot be updated.
My solution to the problem is to use a loader program to load the assemblies into memory and have the application reference those instances rather than the files themselves. This works well when I have to maintain just the executable, but I do not understand how to get the executable to reference the loaded DLLs rather than the files.
Thank you for your help!
Code:
Assembly exeAssembly;
MethodInfo method;
public void RunSystem(string ExePath, string[] DLLPaths)
{
System.Threading.Thread thd;
System.Threading.ThreadStart ts;
FileStream fs;
BinaryReader br;
List<Assembly> dllAssemblies;
//Load the executable file into memory.
fs = new FileStream(ExePath, FileMode.Open);
br = new BinaryReader(fs);
byte[] bin = br.ReadBytes(Convert.ToInt32(fs.Length));
fs.Close();
br.Close();
exeAssembly = Assembly.Load(bin);
//Load each DLL file into memory
foreach (string s in DLLPaths)
{
fs = new FileStream(ExePath, FileMode.Open);
br = new BinaryReader(fs);
bin = br.ReadBytes(Convert.ToInt32(fs.Length));
dllAssemblies.Add(Assembly.Load(bin));
fs.Close();
br.Close();
}
//Now that the assemblies are loaded into memory, the DLL references in the executable
// need to reference the loaded DLL assemblies instead of the DLL files.
//This is what I do not understand how to do.
//............
//Now, create a thread and run the loaded executable on it.
method = exeAssembly.EntryPoint;
ts = new System.Threading.ThreadStart(InvokeExe);
thd = new System.Threading.Thread(ts);
thd.TrySetApartmentState(System.Threading.ApartmentState.STA);
thd.Start();
}
private void InvokeExe()
{
if (method != null)
{
// create an istance of the Startup form Main method
object o = m_Assembly.CreateInstance(m_Method.Name);
// invoke the application starting point
method.Invoke(o, null);
}
}
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|