GetManifestResourceStream : Assembly Load « Assembly « C# / CSharp Tutorial





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() {
    }
}










12.4.Assembly Load
12.4.1.Assemblies
12.4.2.difference between Assembly.Load and Assembly.LoadFrom
12.4.3.Load types(classes) from a Assembly(exe file)
12.4.4.Load the System.Xml assembly using an AssemblyName
12.4.5.Create Type by Assembly qualifed type name
12.4.6.Late Binding
12.4.7.Assembly unloading
12.4.8.Dynamic assembly introspection
12.4.9.Deeper Reflection: Listing All the Types in an Assembly
12.4.10.Assembly Loader
12.4.11.GetManifestResourceStream