2

I have downloaded the demo-repl.zip file from Miguel de Icaza's web site.

I was trying to build certain programs but all is failing. Mine is a simple console application.

Case 1: Only Print the name based on condition. It works well

static void Main(string[] args)
{
  Evaluator.Run("using System;");
  Evaluator.Run("using System.Linq;");
  Evaluator.Run("using System.Collections.Generic;"); 

  string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else} ;");           
  dynamicQuery += ReplaceQuotes("foreach(string name in names)");
   dynamicQuery += ReplaceQuotes("if(name.Contains('name'))");             
  dynamicQuery += "Console.WriteLine(name);";
  Evaluator.Run(dynamicQuery); 

  Console.ReadLine();
}

private static string ReplaceQuotes(string str)
{            
            return str.Replace("'", "\"");
}
}

Case 2: Trying the same with LINQ fails

string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("var result = from name in names where name.Contains('name') select name;");
dynamicQuery += ReplaceQuotes("foreach(string name in result) Console.WriteLine(name);");

Error at runtime being

{interactive}(1,109): error CS1935: An implementation of `Where' query expressio
n pattern could not be found. Are you missing `System.Linq' using directive or `
System.Core.dll' assembly reference?
{interactive}(1,149): error CS1579: foreach statement cannot operate on variable
s of type `object' because it does not contain a definition for `GetEnumerator'
or is not accessible

Case 3: Trying the same with Lambda

string dynamicQuery = ReplaceQuotes("List<string> names = new List<string> {'name1','name2','some thing else'} ;");
dynamicQuery += ReplaceQuotes("names.Where(i => i.Contains('name')).ToList().ForEach(i => Console.WriteLine(i));");

This time the error being

{interactive}(1,83): error CS1061: Type `System.Collections.Generic.List<string>
' does not contain a definition for `Where' and no extension method `Where' of t
ype `System.Collections.Generic.List<string>' could be found (are you missing a
using directive or an assembly reference?)

I searched in the net and found that people are asking to include System.Core and importing the proper namespaces.

I already have these namespace

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Mono.CSharp;

Then what , where, why is it wrong?

Thanks

2 Answers2

2

Add a reference to System.Core to your project or compile command line (-r:System.Core)

Geoff Norton
  • 5,056
  • 1
  • 19
  • 17
0

Add a reference to System.Core and set copy local to true.

Jeff
  • 35,755
  • 15
  • 108
  • 220
  • If you give me ur email, I will send the code that I have with me .. so that u can verify everything. –  Dec 15 '10 at 09:40
  • jeff dot nevins at gmail dot com. I have personally had success with this same scenario. (BTW, if you grab latest of the Mono.CSharp project and compile it, you will probably alleviate this problem as well). See the following: http://www.mono-project.com/CSharp_Compiler (see Obtaining MCS) – Jeff Dec 15 '10 at 14:31
  • Happily you can go ahead... 1 more question, could you please give me the source location of this dll? –  Dec 16 '10 at 05:54
  • Go to the mono project link (http://www.mono-project.com/CSharp_Compiler) and follow the instructions to build MCS (see obtaining MCS section). The two changes I made to the source before building are listed here: http://stackoverflow.com/questions/3407318/mono-compiler-as-a-service-mcs – Jeff Dec 16 '10 at 06:00