XML-Deserialisierung Fehler mit der Wurzel

Ich habe ein problem beim Deserialisieren von XML:

System.InvalidOperationException was unhandled
  Message=There is an error in XML document (0, 0).
  Source=System.Xml
  StackTrace:
       at System.Xml.Serialization.XmlSerializer.Deserialize(XmlReader xmlReader, String encodingStyle, XmlDeserializationEvents events)
       at System.Xml.Serialization.XmlSerializer.Deserialize(TextReader textReader)
       at xsdToObject.Program.Main(String[] args) in D:\Old Documents\Projects\xsdToObject\xsdToObject\Program.cs:line 20
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Xml.XmlException
       Message=Root element is missing.
       Source=System.Xml
       LineNumber=0
       LinePosition=0
       SourceUri=""
       StackTrace:
            at System.Xml.XmlTextReaderImpl.Throw(Exception e)
            at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
            at System.Xml.XmlTextReaderImpl.Read()
            at System.Xml.XmlTextReader.Read()
            at System.Xml.XmlReader.MoveToContent()
            at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationReaderentityColumnsColumnArray.Read3_ArrayOfEntityColumnsColumn()
       InnerException: 

Beim in die innere exception-details der Haupt-Fehlermeldung ist diese:
{"Root element is missing."}

Meine xml Datei ist wie folgt:

<?xml version="1.0" encoding="utf-8" ?>

<entity name="ScheduleTaskEntity" schema="bclscheduler" namespace="http://www.bcl-gaming.com/data/1">
<columns>
<column name="Id" type="identity" />
<column name="UID" type="UID" />
<column name="Timestamp" type="timestamp"/>
<column name="DateCreated" type="datecreated"/>
<column name="Enabled" type="bool" />
<column name="TypeFullname" type="string" size="500" />
<column name="PropertiesLOB" type="propertybag" />
<column name="DisplayName" type="string" size="64" />
<column name="LastDateExecuted" type="datetime" nullable="true" />
<column name="LastMessage" type="string" />
<column name="LastSessionUID" type="guid" nullable="true" />
<column name="CurrentState" type="string" />
<column name="LastDateStarted" type="datetime" nullable="true"/>
<column name="SingleInstance" type="boolean" />
<column name="ExecuteCount" type="bigint" />
<column name="ErrorCount" type="bigint" />      
</columns>
</entity>

Mein code ist wie folgt:

entity e;

System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(typeof(entityColumnsColumn[]));
StreamReader reader = new StreamReader(@"D:\Old Documents\Projects\xsdToObject\xsdToObject\ScheduleTaskEntityTest.xml");
reader.ReadToEnd();
//it gives me the error here
e = (entity)x.Deserialize(reader);
reader.Close();

Irgendwelche Ideen?

InformationsquelleAutor Mazda | 2012-01-30
Schreibe einen Kommentar