Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

Sign your assembly, then in your app.config, specify the fully qualified assembly name. Call Assembly.Load(string), passing the assembly name from your app.config.

NOTE: The assembly you are attempting to load must be in a location where the runtime can find it. Your best bet is either to put it into the Global Assembly Cache, or make sure it is in the same folder as your executing assembly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...