【发布时间】:2025-11-30 22:00:01
【问题描述】:
我的程序有一个pluginManager 模块,它可以加载一个DLL 文件并运行DLL 的方法,但是我需要在Assembly.LoadFile() 之前读取DLL 的属性。我该怎么办?
我看过关于Assembly的文档,他们在Assembly.LoadFile()之后读取属性,你知道Assembly没有UnLoad()方法,所以我必须在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();
}
}
}
【问题讨论】:
-
是否可以强制将可查询的元数据放在目标 dll 旁边的单独文件中?
-
你的意思是我可以为插件 dll 文件创建一个 xml 文档?
-
您应该发布更多代码,这可能是一种更好的整体方式来做您想做的事情,这听起来可能会从一些设计调整中受益。或在 StackExchange -CodeReview 上发帖。
-
我想过滤同一个 DLL,如果我加载同一个 DLL 程序会崩溃
标签: c# dll .net-assembly