Using the Mono C # Compiler as a Service (error)

I'm relatively new to Mono, and I'm trying to add C # scripting capabilities to my application. I found this blog post by Miguel de Icaza. The way to call the C # compiler as a service is to enable Mono.CSharp and use the Evaluator class, in particular the Evaluate or Run methods. This is described here .

So here is my sample code (obtained from other blog posts on the Internet on this subject, yes, I did my search on the Internet)

using System;
using Mono.CSharp;

namespace EvalTest
{
  public class Test
  {
    static void Main(string [] args)
    {
      Mono.CSharp.Evaluator.Evaluate("using System;");
      Mono.CSharp.Evaluator.Run("using System;");
    }
  }
}

And when we try to compile it, I get the following errors:

eval.cs(10,19): error CS0234: The type or namespace name `Evaluator' does not exist in the namespace `Mono.CSharp'. Are you missing an assembly reference?
eval.cs(11,19): error CS0234: The type or namespace name `Evaluator' does not exist in the namespace `Mono.CSharp'. Are you missing an assembly reference?

Linux OSX, Mono, Silverlight . stackoverflow , Miguel . ? - , ? .

+3
2

:

, `gmcs.exe '

? , ( Test.cs):

c:\Users\Jon\Test>copy "c:\Program Files (x86)\Mono-2.8"\lib\mono\2.0\gmcs.exe .
        1 file(s) copied.

c:\Users\Jon\Test>gmcs /r:gmcs.exe Test.cs

c:\Users\Jon\Test>mono Test.exe

Unhandled Exception: System.ArgumentException:
  The expression did not set a result
  at Mono.CSharp.Evaluator.Evaluate (System.String input) [...]
  at EvalTest.Test.Main (System.String[] args) [...]

, - using. :

Mono.CSharp.Evaluator.Run("System.Console.WriteLine(5 + 5);");
+6

?

, 95% . :

, `gmcs.exe '

+2

Source: https://habr.com/ru/post/1783001/


All Articles