Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
212 views
in Technique[技术] by (71.8m points)

reflection - Getting Information about a assembly which is present in Solution

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

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

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...