Scenario: I want to load a assembly at run time which is present in Solution.
The belo code will not work as it is not present in Cuurent App Domain.
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
Also if i will search in referenced assemblies, then also it can not be found as it is not referenced. So the below code will also not work:
public static IEnumerable<Assembly> GetAssemblies()
{
var list = new List<string>();
var stack = new Stack<Assembly>();
stack.Push(Assembly.GetEntryAssembly());
do
{
var asm = stack.Pop();
yield return asm;
foreach (var reference in asm.GetReferencedAssemblies())
if (!list.Contains(reference.FullName))
{
stack.Push(Assembly.Load(reference));
list.Add(reference.FullName);
}
}
while (stack.Count > 0);
}
Do you guyz have some suggestion ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…