Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Run time compilation with ASSEMBLIES?!?

Run time compilation with ASSEMBLIES?!?

Scheduled Pinned Locked Moved C#
helpquestionworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    EdgarBM
    wrote on last edited by
    #1

    Hi, I'm compiling in run time with a code like this: CSharpCodeProvider codeProvider = new CSharpCodeProvider(); ICodeCompiler icc = codeProvider.CreateCompiler(); System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); parameters.GenerateExecutable = false; parameters.GenerateInMemory = true; CompilerResults results = icc.CompileAssemblyFromSource(parameters, txtSource ); if (results.Errors.Count > 0) { foreach(CompilerError CompErr in results.Errors) { txtErr.Text += "Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine; } } else { Assembly assembly = results.CompiledAssembly; Type t = assembly.GetType("MyNamespace.MyClass"); MethodInfo me = t.GetMethod("MyMethod"); object result; result = t.InvokeMember("MyMethod2", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod , null, null, null ); MessageBox.Show ( ((int)result).ToString() ); // get the result as string } } //(provided by Wiktor Zychla) The problem is: how can I specify reference assemblies to the run time compiled assembly?, is it possible? 'ReferencedAssemblies' in 'CompilerParameters' is only of read mode, so it's not possible to set them...I'm wrong? Thanks in advance, Edgar __________________________________________ Edgar Berengena Moreno Software Engineer Appeyron Research

    S 1 Reply Last reply
    0
    • E EdgarBM

      Hi, I'm compiling in run time with a code like this: CSharpCodeProvider codeProvider = new CSharpCodeProvider(); ICodeCompiler icc = codeProvider.CreateCompiler(); System.CodeDom.Compiler.CompilerParameters parameters = new CompilerParameters(); parameters.GenerateExecutable = false; parameters.GenerateInMemory = true; CompilerResults results = icc.CompileAssemblyFromSource(parameters, txtSource ); if (results.Errors.Count > 0) { foreach(CompilerError CompErr in results.Errors) { txtErr.Text += "Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine; } } else { Assembly assembly = results.CompiledAssembly; Type t = assembly.GetType("MyNamespace.MyClass"); MethodInfo me = t.GetMethod("MyMethod"); object result; result = t.InvokeMember("MyMethod2", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod , null, null, null ); MessageBox.Show ( ((int)result).ToString() ); // get the result as string } } //(provided by Wiktor Zychla) The problem is: how can I specify reference assemblies to the run time compiled assembly?, is it possible? 'ReferencedAssemblies' in 'CompilerParameters' is only of read mode, so it's not possible to set them...I'm wrong? Thanks in advance, Edgar __________________________________________ Edgar Berengena Moreno Software Engineer Appeyron Research

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      CompilerParameters constructor


      She's so dirty, she threw a boomerang and it wouldn't even come back.

      E 1 Reply Last reply
      0
      • S Stephane Rodriguez

        CompilerParameters constructor


        She's so dirty, she threw a boomerang and it wouldn't even come back.

        E Offline
        E Offline
        EdgarBM
        wrote on last edited by
        #3

        GREAT! Fast and simple. Thank you, Stephane. __________________________________________ Edgar Berengena Moreno Software Engineer Appeyron Research

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups