C# - Dynamic code, reference issues and placement -


in code, i'm reading text file, compiling , trying run it, have issue references (i think) code:

using system; using system.collections.generic; using system.windows; using system.runtime.interopservices; using system.text; using system.codedom.compiler; using system.io; using microsoft.csharp; using system.reflection;   namespace ifcviewer {  static class program {     static public void main()     {          string code_file = system.io.file.readalltext(@"c:\tmp\my_code.txt");          /* element db */         list<db.ifcarray> element_list = new list<db.ifcarray>();          /* relationships db */         list<db.relobj> rel_list = new list<db.relobj>();          bool flag = false;          compileandrun(code_file);       }      static void compileandrun(string code)     {         compilerparameters compilerparams = new compilerparameters();         string outputdirectory = directory.getcurrentdirectory();          compilerparams.generateinmemory = true;         compilerparams.treatwarningsaserrors = false;         compilerparams.generateexecutable = false;         compilerparams.compileroptions = "/optimize";          string[] references = { "system.dll","system.windows.forms.dll"};         compilerparams.referencedassemblies.addrange(references);          csharpcodeprovider provider = new csharpcodeprovider();         compilerresults compile = provider.compileassemblyfromsource(compilerparams, code);          if (compile.errors.haserrors)         {             string text = "compile error: ";             foreach (compilererror ce in compile.errors)             {                 text += "rn " + ce.tostring();             }             throw new exception(text);         }          module module = compile.compiledassembly.getmodules()[0];         type mt = null;         methodinfo methinfo = null;          if (module != null)         {             mt = module.gettype("ifcviewer.program");         }          if (mt != null)         {             methinfo = mt.getmethod("run_my_code");         }          if (methinfo != null)         {             console.writeline(methinfo.invoke(null, new object[] {}));         }     } 

the text file contains following code:

using system; using system.collections.generic; using system.windows.forms; using system.runtime.interopservices; using system.text; using system.codedom.compiler; using system.io; using microsoft.csharp; using system.reflection;  namespace ifcviewer { public static class dynacode {         static public void run_my_code(list<db.ifcarray> element_list,list<db.relobj> rel_list,bool flag)             {                 messagebox.show("dynamic code running!!");             }       }  } 

the db class defined on different file same namespace (ifcviewer).

namespace ifcviewer { public static class db {   +       public class ifcarray  +       public class relobj  } 

i reference error: error cs0234: type or namespace name 'db' not exist in namespace 'ifcviewer' (are missing assembly reference?) when try compile , run code file, compile , run method work, i've tested it.

any ideas?


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -