.netdynamic-assemblies

.net dynamic assemblies


I was recently asked if I knew anything about Dynamic Assemblies in .Net. The short answer was - I don't.

I have found plenty of articles that describe how to create a dynamic assembly but none that truely explain the following:

Any explanations to the above would be very much appreciated.

Many thanks.


Solution

  • This article is a bit dated and the code is a bit 'rustic' but I would say it is one of the most accessible articles regarding dynamic compilation and some of the salient issues.

    It is where I learned to compile assemblies on the fly, both in memory when I did not need to unload or control security, and to a temp file to be loaded with remoting to allow unloading.

    A real world example: An online .net regex tool that accepts c# code for a replacer method that is dynamically compiled into a sandboxed assembly, used to perform the replacement and discarded. This strategy worked just fine, but the possibility of malicious code being injected regardless of sandboxing was just too great so the idea was eventually scrapped.

    Good luck.