|
-
Mar 20th, 2012, 05:06 PM
#1
Thread Starter
Lively Member
Loading File Problem
Not sure what the deal is on this, I thought I had this workign once.
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(Stream stream)
at e_Soft_Addition_L_1.Lesson.OpenToolStripMenuItem_Click(Object sender, EventArgs e) in C:\Users\Admin\documents\visual studio 2010\Projects\e-Soft Addition L-1\e-Soft Addition L-1\Lesson.vb:line 421
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoCompo nentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at e_Soft_Addition_L_1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
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
LineNumber=0
LinePosition=0
Message=Root element is missing.
Source=System.Xml
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.XmlSerializationReaderStorage.Read3_Storage()
InnerException:
Code:
Code:
Private FileDialog As SaveFileDialog
Public Sub New()
InitializeComponent()
FileDialog = New SaveFileDialog()
FileDialog.Filter = "e Soft Lesson | *.les"
FileDialog.DefaultExt = "les"
End Sub
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
'Load Action
Dim AppSerializer As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(Storage))
Dim AppFileStream As FileStream = New FileStream(".les", FileMode.Open)
OpenFileDialog1.Filter = "e Soft Lesson | *.les"
OpenFileDialog1.DefaultExt = "les"
OpenFileDialog1.Title = "Windows Explorer"
OpenFileDialog1.ShowDialog()
Storage = CType(AppSerializer.Deserialize(AppFileStream), Storage)
UpdateForm()
AppFileStream.Close()
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
'Save Action
Dim dr As DialogResult = FileDialog.ShowDialog()
Dim fileName As String = FileDialog.FileName
Dim AppSerializer As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(GetType(Storage))
Dim fileStream As New System.IO.FileStream(fileName, IO.FileMode.Create)
Dim SW As New System.IO.StreamWriter(fileStream)
If Storage.Name = "" Then
MsgBox("Please Enter Your Name And try Again")
Else
AppSerializer.Serialize(SW, Storage)
SW.Close()
End If
End Sub
The code worked fine in another program so not sure why its not working well here.
-
Mar 21st, 2012, 04:57 AM
#2
Re: Loading File Problem
Looks like you're trying to deserialize an object from invalid XML.
Message=Root element is missing.
Source=System.Xml
SourceUri=""
I saw the above in the stack trace you posted. Seems the XML document doesnt have a root element.
-
Mar 21st, 2012, 03:27 PM
#3
Thread Starter
Lively Member
Re: Loading File Problem
ok so where is the error code wise? Sorry im still newb so a code exsample would help too please ty.
-
Mar 21st, 2012, 03:32 PM
#4
Re: Loading File Problem
No...what I'm saying is that there is something wrong with the XML data itself, not the code.
-
Mar 30th, 2012, 05:59 PM
#5
Thread Starter
Lively Member
Re: Loading File Problem
oo ok so how do i fix that?
-
Mar 30th, 2012, 08:00 PM
#6
Re: Loading File Problem
The error itself is a clue. You may need a Root node in your XML Data like:-
Code:
<Root>
<WhateverData>
</WhateverData>
</Root>
-
Mar 30th, 2012, 10:10 PM
#7
Thread Starter
Lively Member
Re: Loading File Problem
Im a newb if u want i can let u team view me. I understand that somethign wrong in the xml file but its a blank text document so nothing o be wrong.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|