3

I followed this thread to install Mono on my Fedora box:

Install Mono on Centos 5.5 using YUM

However, when I try and compile my program using:

 gmcs foo.cs

I get:

  foo.cs(11,44): error CS0117: `System.IO.File' does not contain a definition for `ReadLines'
/opt/novell/mono/lib/mono/2.0/mscorlib.dll (Location of the symbol related to previous error)

Compilation failed: 1 error(s), 0 warnings

The line in question is:

 using System;
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;

 foreach(int currentMax in File.ReadLines(args[0]).Select(int.Parse)) 
 {
     ...
 }

Can anyone point me in the right direction?

Community
  • 1
  • 1
Jim
  • 53
  • 1
  • 4
  • Have you tried ReadAllLines? Maybe it's defined :) – kol Dec 04 '11 at 01:18
  • Which version of mono? If it's an older version, it may be that the feature isn't implemented yet. I would try upgrading to the latest version if possible (2.10 I believe) – Ken Wayne VanderLinde Dec 04 '11 at 01:18
  • I am on 2.10:# mono --version Mono JIT compiler version 2.10.2 (tarball Mon Apr 18 18:57:39 UTC 2011) Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com TLS: __thread SIGSEGV: altstack Notifications: epoll Architecture: x86 Disabled: none Misc: debugger softdebug LLVM: supported, not enabled. GC: Included Boehm (with typed GC and Parallel Mark) – Jim Dec 04 '11 at 01:43

2 Answers2

2

So it looks like the problem is that you are using the gmcs compiler, which is designed specifically for targeting the .Net 2.0 runtime. The list of C# compilers for mono is:

  • mcs - .Net 1.1 runtime (deprecated)
  • gmcs - .Net 2.0 runtime
  • smcs - .Net 2.1 runtime
  • dmcs - .Net 4.0 runtime

(see here for more details)

So the compiler you should be using for targeting .Net 4.0 is dmcs. Instead, if you actually intended to target .Net 2.0, then use the File.ReadAllLines method that @kil and @minitech talked about.

Ken Wayne VanderLinde
  • 18,915
  • 3
  • 47
  • 72
0

I believe you want File.ReadAllLines.

Ry-
  • 218,210
  • 55
  • 464
  • 476