How can I use CodeDOM to create and load an assembly in an AppDomain?

Chicken and egg problem. You need a little bootstrapper assembly that you can load in the new AppDomain. With a well-known class that loads the CodeDom generated assembly and gets it going.

Doing this with GenerateInMemory is pretty pointless, you would have to serialize that into the new AppDomain. That's just a bunch of overhead, might as well load it from disk, it is there anyway. And it is already in memory. The file system cache's memory. Loading it will be very fast since it doesn't actually have to be read off the disk.


I found the answer that I was looking for at http://www.softwareinteractions.com/blog/2010/2/7/loading-and-unloading-net-assemblies.html. He has a nice article detailing the creation of an AppDomain and loading an assembly as a plugin. I followed his example and was able to create an AppDomain, create a proxy for my ExpressionEvaluator class factory and successfully call it and receive results.