Assembly.GetExecutingAssembly() : Assembly « System.Reflection « C# / C Sharp by API






Assembly.GetExecutingAssembly()

  
 
  
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;

public class Loader {
    static Dictionary<string, Assembly> libs = new Dictionary<string, Assembly>();

    static void Main() {
        AppDomain.CurrentDomain.AssemblyResolve += FindAssem;
        Program.Go();
    }

    static Assembly FindAssem(object sender, ResolveEventArgs args) {
        string shortName = new AssemblyName(args.Name).Name;
        if (libs.ContainsKey(shortName)) return libs[shortName];

        using (Stream s = Assembly.GetExecutingAssembly().GetManifestResourceStream("Libs." + shortName + ".dll")) {
            byte[] data = new BinaryReader(s).ReadBytes((int)s.Length);
            Assembly a = Assembly.Load(data);
            libs[shortName] = a;
            return a;
        }
    }
}

public class Program {
    public static void Go() {
    }
}

 

   
    
  








Related examples in the same category

1.Assembly.CodeBase
2.Assembly.EntryPoint
3.Assembly.EscapedCodeBase
4.Assembly.Evidence
5.Assembly.FullName
6.Assembly.GetCallingAssembly()
7.Assembly.GetCustomAttributes
8.Assembly.GetEntryAssembly()
9.Assembly.GetExportedTypes
10.Assembly.GetName
11.Assembly.GetReferencedAssemblies
12.Assembly.GetTypes()
13.Assembly.GlobalAssemblyCache
14.Assembly.Load(AssemblyName name2)
15.Assembly.Load(String name)
16.Assembly.LoadFrom(String assemblyName)
17.Assembly.Location