Creating a dynamic assembly and module
When your code has gone through the compiler and been outputted to a binary that runs. That code is considered static and cannot be modified. The binary represented as an assembly is completely static; not only can you not modify code in it but you also cannot add to it either. It would be a security risk if arbitrary code could go and modify running code.
To overcome this, you have to explicitly create a new assembly on the fly that only exists in memory. This is known as a dynamic assembly.
All assemblies have also the concept of modules. An assembly must have at least one module. A module is a container that holds the concrete IL code and only metadata related to it, while an assembly is a higher-order abstract container that contains more metadata and could, in fact, refer to multiple .dll files. Generally, you’ll only see a one-to-one relationship between an assembly and a module.
It is very easy to get started with this:
...