[Mono-list] Error when i test Linq
Jean-Alexandre Peyroux
peyroux at gmail.com
Tue Oct 23 17:33:54 EDT 2007
Hello,
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
root.Element("utilisateurs").Elements("utilisateur")
select
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)
[0x00000]
at System.Xml.Linq.XText.WriteTo (System.Xml.XmlWriter w)
[0x00000]
at System.Xml.Linq.XNode.ToString (SaveOptions options)
[0x00000]
at System.Xml.Linq.XNode.ToString () [0x00000]
at System.Text.StringBuilder.Append (System.Object value)
[0x00000]
at System.Xml.Linq.XElement.get_Value () [0x00000]
at
Linquou+<>c__CompilerGenerated0.<Main>c__1[XElement,<>__AnonType0`2]
(System.Xml.Linq.XElement u) [0x00000]
at
System.Linq.Enumerable+<>c__CompilerGenerated13`2[System.Xml.Linq.XElement,<>__AnonType0`2[System.String,System.String]].MoveNext
() [0x00000]
at Linquou.Main (System.String[] args) [0x00000]
xml file for my exemple is :
<?xml version="1.0" encoding="utf-8"?>
<carnet>
<utilisateurs>
<utilisateur>
<nom>Peyroux</nom>
<prenom>Jean Alexandre</prenom>
</utilisateur>
<utilisateur>
<nom>Pommereau</nom>
<prenom>Eric</prenom>
</utilisateur>
<utilisateur>
<nom>James</nom>
<prenom>Sylvain</prenom>
</utilisateur>
</utilisateurs>
</carnet>
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.
regards
More information about the Mono-list
mailing list