我可以像使用 excel 一样加载System.DirectoryServices.AccountManagement
(或多或少)吗?我不想在我的项目中引用 dll,而是在运行时加载它。
如何加载任何框架dll?
-
Assembly.LoadFile(...);
? - 但随后我需要得到它的路径。如何?
Excel示例:
dynamic excel = Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application"));
我希望我可以使用这样的动态对象:
PrincipalContext context1 = new PrincipalContext(ContextType.Domain); // referenced dll
dynamic context2 = ???; // loaded at runtime
引用的 dll/程序集可能生成到您的 exe 文件所在的文件夹中。您可以从那里加载它们(使用 Sytem.AppDomain.Current.BaseDirectory 获取路径)。没有这样一种方法可以像您的要求那样在没有指定路径的情况下加载程序集,或者您可以按照您所描述的内容实现它