Reputation: 3641
I want to Load and Create Assemblies during runtime and someone told me to use the Namespace System.Reflection.Assembly and System.Reflection.Emit.
Only reference I found was on the msdn, but it´s not as good to work with it when you don´t know where and how to start. I already googled but I didn´t find any useful tutorials/samples/references.
Can someone explain the functionality to me or give me some samples/tutorials?
Upvotes: 0
Views: 157
Reputation: 6971
http://msdn.microsoft.com/en-us/library/saf5ce06.aspx
public static void CompileScript(string source)
{
CompilerParameters parms = new CompilerParameters();
parms.GenerateExecutable = true;
parms.GenerateInMemory = true;
parms.IncludeDebugInformation = false;
parms.ReferencedAssemblies.Add("System.dll");
// Add whatever references you might need here
CodeDomProvider compiler = CSharpCodeProvider.CreateProvider("CSharp");
CompilerResults results = compiler.CompileAssemblyFromSource(parms, source);
file.move(results.CompiledAssembly.Location,"c:\myassembly.dll");
}
Upvotes: 4
Reputation: 100547
One possible way to create assembly from a source file(s) is simply run CSC (C# command line compiler) passing in source files and references as arguments. Manual IL generation is likely way too advanced, especially if you want to build assemblies from code provided by someone else.
To load - use Assembly.Load.
Upvotes: 0