C#通过Assembly.Load加载程序集

来源:https://bbs.csdn.net/topics/391975530?page=1

 

分两种情况:

1、需要加载的程序集已经在程序中被引用了,则直接从当前程序域中查找即可:

Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(x => x.GetName().Name.Contains("theAssemblyName"));

 

2、需要加载的程序集未被加载,则使用程序集名称加载:

Assembly assembly = Assembly.Load(@"theAssemblyName, Version=55.0.0.0, Culture=neutral, PublicKeyToken=ef0f902af9dee505");

 

Tips:如何获取dll文件的PublicKeyToken,Culture,Version

Assembly assembly = Assembly.LoadFile(@"C:\Program Files\ReferencedAssemblies\theAssemblyName.dll");
string name = assembly.FullName;

 

 

 

你可能感兴趣的:(C#)