My program have a pluginManager module, it can load a DLL file and run DLL's methods, but I need read the DLL properties before Assembly.LoadFile()
. What should I do?
I readed about Assembly documents, they read properties after Assembly.LoadFile()
, you know Assembly no UnLoad() Method, so I must read properties before LoadFile()
private void ImprotZip(string path)
{
/*
1、create tempDir, uppackage to tempDir
2、Load Plugin DLL, Load plugin dependent lib DLL
*/
string tempDirectory = CreateRuntimeDirectory(path);
string[] dllFiles = Directory.GetFiles(tempDirectory);
///Load DlL
foreach(string dll in dllFiles)
{
ImprotDll(dll, false);
}
string libPath = string.Format("{0}\\lib\\", tempDirectory);
if (!Directory.Exists(libPath))
return;
string[] dlls = Directory.GetFiles(libPath);
///Load plugin dependent lib DLL
foreach(string dll in dlls)
{
try
{
//filtering same DLL
//if(Dll.properties.AssemblyProduct != "something")
//continue;
Assembly.LoadFile(dll);
}
catch(Exception e)
{
e.Log();
}
}
}
You can load assemblies into a reflection-only context using Assembly.ReflectionOnlyLoad
.
I would still create an app domain for the reflection only context so you can unload the domain when you are done. You can create app domains by using the AppDomain.CreateDomain
method. You should be doing this for plugins anyway so you can unload them when you are done.
FileVersionInfo.GetVersionInfo
is exactly what you're looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With