[Mono-list] Error when i test Linq

Jean-Alexandre Peyroux peyroux at gmail.com
Tue Oct 23 17:33:54 EDT 2007


When i test simple LinqToXml exemple with olive module, i have an error. 
I would know if an error is in my code.

---- 8< --- code --- 8< ----
using System;
using System.Linq;
using System.Xml.Linq;
using System.Collections.Generic;

class Linquou
    public static void Main(string[] args)
        XElement root = XElement.Load(@"utilisateur.xml");
        if(root.Element("utilisateurs") != null) {
            var listUser = from u in
                           new { Nom = u.Element("nom").Value,
						         Prenom = u.Element("prenom").Value
            foreach(var u in listUser) {
                System.Console.WriteLine("An user: {0} {1}", u.Prenom, u.Nom);
---- 8< --- end code --- 8< ----

I compile this code with : 

gmcs -r:System.Core.dll -r:lib/System.Xml.Linq -langversion:linq sampleLinq.cs 

Compilation return 0 error but when i run sampleLinq.exe i have this
error :

[mono] ~/Codaz/Cs/linqt @ make
gmcs -r:System.Core.dll -langversion:linq  -r:lib/System.Xml.Linq
exemple2.cs -out:exemple2.exe
[mono] ~/Codaz/Cs/linqt @ mono exemple2.exe 

Unhandled Exception: System.InvalidOperationException: This XmlWriter
does not accept Text at this state Start.
at System.Xml.XmlTextWriter.ShiftStateContent (System.String occured,
Boolean allowAttribute) [0x00000] 
at System.Xml.XmlTextWriter.WriteString (System.String text)
at System.Xml.Linq.XText.WriteTo (System.Xml.XmlWriter w)
at System.Xml.Linq.XNode.ToString (SaveOptions options)
at System.Xml.Linq.XNode.ToString () [0x00000] 
at System.Text.StringBuilder.Append (System.Object value)
at System.Xml.Linq.XElement.get_Value () [0x00000] 
(System.Xml.Linq.XElement u) [0x00000] 
() [0x00000] 
at Linquou.Main (System.String[] args) [0x00000] 

xml file for my exemple is :

<?xml version="1.0" encoding="utf-8"?>
		<prenom>Jean Alexandre</prenom>

Finaly my mono version is : 
[mono] ~/Codaz/Cs/linqt @ mono --version
Mono JIT compiler version 1.2.5 (/trunk/ r87936)

I hope you forgive me for my bad english.


More information about the Mono-list mailing list