Results 1 to 7 of 7

Thread: Loading File Problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2011
    Posts
    65

    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.

  2. #2
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2011
    Posts
    65

    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.

  4. #4
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    Re: Loading File Problem

    No...what I'm saying is that there is something wrong with the XML data itself, not the code.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2011
    Posts
    65

    Re: Loading File Problem

    oo ok so how do i fix that?

  6. #6
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    9,017

    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>
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2011
    Posts
    65

    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
  •  



Click Here to Expand Forum to Full Width