C# 模块化(组装)插件系统
我一直在寻找一种方法来延迟加载程序集,并能够再次重用相同的文件程序集,而无需服务器重新加载它们。据我所知,应用程序域会一直保存它们,直到应用程序关闭 假设我有framework.dll并希望加载程序集,但我需要使用不同的函数反复使用/调用相同的程序集。你将如何编程 我一直在想这样的事情:C# 模块化(组装)插件系统,c#,asp.net,.net-assembly,C#,Asp.net,.net Assembly,我一直在寻找一种方法来延迟加载程序集,并能够再次重用相同的文件程序集,而无需服务器重新加载它们。据我所知,应用程序域会一直保存它们,直到应用程序关闭 假设我有framework.dll并希望加载程序集,但我需要使用不同的函数反复使用/调用相同的程序集。你将如何编程 我一直在想这样的事情: public object[] InvokeAsmMethod(string AsmFile, object AsmType, AsmInstance, object Parameters) {
public object[] InvokeAsmMethod(string AsmFile, object AsmType, AsmInstance,
object Parameters)
{
try
{
Assembly loadedAssembly = Assembly.LoadFile(AssemblyFile);
loadedAssembly = typeof(AsmType).Assembly;
....
}
catch (FileLoadException ex)
{
throw new System.InvalidOperationException(ex.ToString());
} // The Assembly has already been loaded.
catch (BadImageFormatException ex)
{
throw new System.InvalidOperationException(ex.ToString());
} // If a BadImageFormatException exception is thrown, the file is not an assembly.
catch (Exception ex)
{
throw new System.InvalidOperationException(ex.ToString());
} // If a BadImageFormatException exception is thrown, the file is not an assembly.
}
相反,要使用方法加载和调用外部程序集中的函数,请使用方法加载它并从中返回对象实例。然后你可以简单地重复使用它,而不需要重新加载。是的,这就是我想要实现的,但我需要一些例子。