I do this in order to dynamically generate code:
Code:
CodeDomProvider provider = CodeDomProvider.CreateProvider("CSharp");
CompilerParameters cp = new CompilerParameters();
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add(@"C:\Users\Gift\Desktop\MJsniffer\MJSniffer\Commands\bin\Debug\Commands.dll");
cp.GenerateInMemory = true;
cp.OutputAssembly = "myasm.dll";
CompilerResults result = provider.CompileAssemblyFromSource(cp, lcCode);
Assembly loAssembly = result.CompiledAssembly;
object loObject = loAssembly.CreateInstance("ScriptSpace.ScriptClass");
The problem is that this new assembly doesn't work with the assembly I add on the read line. The problems are that it doesn't find the methods inside it. I have a class like
Code:
namespace A
{
static class B
{
static void c() {}
}
}
Which is in the Commands.dll. I cannot use the B.c() method. I created two assemblies to reproduce this and I see that I can still not use a static method from one assembly to the other.
I can also not instantiate any class inside the assembly or use any variable.
Am I doing something wrong here? How can you make one assembly correctly use another one?