I have some C# code (let's call it "script") I am compiling at runtime. It uses an interface in my main program that I use to access its functions. Once compiling is done I have CompilerResults.CompiledAssembly
in which case I can CreateInstance(Type)
.
Once I am done using the script I would like to unload completely. From what I understand, I can only do this if I create a separate app domain: Loading DLLs into a separate AppDomain
I had some questions specific to my implementation:
ReferencedAssemblies.Add(typeof(Interface).Assembly.Location)
before I compile.CompilerParameters GenerateInMemory=true
, or do I have to save it somewhere?Answers in order:
Not so long as you set the domain setup's base path to your own.
AppDomainSetup.ApplicationBase = AppDomain.CurrentDomain.SetupInformation.ApplicationBase;
No you don't need to save it and it doesn't sound like it would benefit you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With