I'm working on a utility that will allow you to compile a piece of code while running. I'd like to put that code in a temporary assembly and load it.
var provider = new CSharpCodeProvider();
var parameters = new CompilerParameters {
GenerateInMemory = true,
OutputAssembly = "SomeName"
};
... // add assembly references
var results = provider.CompileAssemblyFromSource(parameters, mySourceCode);
var payload = Activator.CreateInstance(results.CompiledAssembly.GetTypes().First());
Later, after the user makes a change to the code, I'd like to create a new temporary assembly with the changes. However, it seems like the old version is sticking around and confusing the rest of my code. How do I unload the original temporary assembly?