How do you load the built-in assemblies that you put in your main assembly?

What is the best practice for merging one assembly into another? I have an assembly that I am handing out, but I have several third-party assemblies that I use in it, and I don't want to distribute more than one.

So, I would like to compile a couple of collections in what I will distribute so that they are just inline.

What is the best practice for this? I know that I can put other assemblies in my project and install them in a "built-in resource", but how do you release them again, which means how you can get it in a place where I can instantiate classes defined in this built-in assembly ?

I saw the Assembly.Load method, but it looks like it needs a file path. Is there any other way to load embedded assemblies? How do you tell the Load method where the assembly is?

Once you load the inline assembly, is it just magical in scope and can I freely create classes from it?

+3
source share
2 answers

Here is the assembly. Download (byte []) the overload that you can use to load assemblies from an array in memory. If I remember correctly, for example, LINQPad works . This can be done here if the assembly is an instance of System.Reflection.Assembly containing other assemblies as managed resources:

Stream embedded = assembly.GetManifestResourceStream ("asm.dll");
byte [] buffer = new byte [embedded.Length];
using (embedded) {
    int length = buffer.Length;
    int offset = 0;
    while (length > 0) {
        int read = assemblyStream.Read (buffer, offset, length);
        if (read == 0)
            break;

        length -= read;
        offset += read;
    }
}

Assembly assembly = Assembly.Load (buffer);

, , Assembly.LoadFile.

System.Reflection.Assembly, , , .

+5

ILMerge, , , .

+5

Source: https://habr.com/ru/post/1705534/


All Articles