2012-02-06 5 views
5

실패, 다음 코드는 XML 문서에 실패 XDocument.Load이 LoadOptions.PreserveWhitespace를 사용하는 경우모노 - XDocument.Load 모노 버전 2.10.5을 사용 LoadOptions.PreserveWhitespace

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

namespace TestXDocument 
{ 
    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      Stream s = File.Open("Settings.xml", FileMode.Open); 
      XDocument d = XDocument.Load(s, LoadOptions.PreserveWhitespace); 
      s.Close(); 
      d.Save("Settings.xml"); 
     } 
    } 
} 

에만 발생합니다. 이 문제를 해결하거나 문제를 해결하는 방법에 대한 아이디어가 있습니까?

Linux Mint 12 및 Ubuntu 11.10에서 테스트되었습니다.

Unhandled Exception: System.InvalidOperationException: This XmlWriter does not accept Text at this state Prolog. 
    at System.Xml.XmlTextWriter.ShiftStateContent (System.String occured, Boolean allowAttribute) [0x00000] in <filename unknown>:0 
    at System.Xml.XmlTextWriter.WriteString (System.String text) [0x00000] in <filename unknown>:0 
    at System.Xml.DefaultXmlWriter.WriteString (System.String text) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XText.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.String filename, SaveOptions options) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.String filename) [0x00000] in <filename unknown>:0 
    at TestXDocument.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: This XmlWriter does not accept Text at this state Prolog. 
    at System.Xml.XmlTextWriter.ShiftStateContent (System.String occured, Boolean allowAttribute) [0x00000] in <filename unknown>:0 
    at System.Xml.XmlTextWriter.WriteString (System.String text) [0x00000] in <filename unknown>:0 
    at System.Xml.DefaultXmlWriter.WriteString (System.String text) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XText.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.WriteTo (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.Xml.XmlWriter w) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.String filename, SaveOptions options) [0x00000] in <filename unknown>:0 
    at System.Xml.Linq.XDocument.Save (System.String filename) [0x00000] in <filename unknown>:0 
    at TestXDocument.MainClass.Main (System.String[] args) [0x00000] in <filename unknown>:0 
+2

Mono 문제는 공식 bugzilla (http://www.mono-project.com/Bugs)를 통해보고하는 방법을 배워야합니다. –

+0

질문이 있습니까? – sehe

+0

여기에있는 질문은 어떻게 해결할 수 있습니까? –

답변

3

내가 우분투 11.10에 모두 코드 예제에서 같은 문제를 재현 할 수 :

다음은 예외입니다. 당신이 말했듯이 Windows 플랫폼에는 문제가 없습니다. Mono 런타임에는 XDocument의 Save 메서드에 특정 버그가있어 예기치 않은 오류가 발생하는 것으로 보입니다. 이 문제는 소프트웨어 패치를 위해 Mono 런타임 팀에보고하고 싶습니다.

그러나, 나는 여기에 가져올 수있는 가능한 해결 방법은,

d.Root.Save("Settings1.xml"); 

그것은 우리가하여 XDocument에서 발생으로하여 XElement의 저장 방법은 문제가없는 것으로 보인다.

+0

좋은 해결 방법. 감사! 'PreserveWhitespace' 옵션은 여전히''을''로 바꾸고 있기 때문에 원본 파일의 완벽한 공백 표현이 아닙니다. 나는 Windows에서만 이것을 체크하지 않았고, Mac에서는'Mono 2.10.9'를 사용했다. – cod3monk3y

+0

불행히도 이것은 나를 위해 작동하지 않습니다. 'Info.plist' 파일은 DOCTYPE 태그' cod3monk3y