EDN Admin
Well-known member
System.InvalidOperationException was unhandled<br/>
HResult=-2146233079<br/>
Message=There was an error generating the XML document.<br/>
Source=System.Xml<br/>
StackTrace:<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)<br/>
at WindowsApplication1.Form1.SavePlayList(String Filename) in C:UsersRocketShipDesktopF Drive - My FilesOrganized FilesProjectsvidplayerExamplevidplayerExampleForm1.vb:line 403<br/>
at WindowsApplication1.Form1.ToCRDelimitedTextFileToolStripMenuItem_Click(Object sender, EventArgs e) in C:UsersRocketShipDesktopF Drive - My FilesOrganized FilesProjectsvidplayerExamplevidplayerExampleForm1.vb:line 739<br/>
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)<br/>
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)<br/>
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)<br/>
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)<br/>
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)<br/>
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br/>
at System.Windows.Forms.Control.WndProc(Message& m)<br/>
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br/>
at System.Windows.Forms.ToolStrip.WndProc(Message& m)<br/>
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br/>
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br/>
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.Run(ApplicationContext context)<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br/>
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException: System.InvalidOperationException<br/>
HResult=-2146233079<br/>
Message=Token StartElement in state Epilog would result in an invalid XML document.<br/>
Source=System.Xml<br/>
StackTrace:<br/>
at System.Xml.XmlTextWriter.AutoComplete(Token token)<br/>
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteArray(String name, String ns, Object o, Type type)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElement(String name, String ns, Object o, Type ambientType)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElements()<br/>
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_AvbMediaPlayerPlaylist(Object o)<br/>
InnerException: <br/>
Any ideas?
I have made this serialization sub:
<pre class="prettyprint lang-vb" style=" Sub SavePlayList(ByVal Filename As String)
Dim PlaylistItems As New List(Of MyVideo)
For Each Item In ListBox1.Items
Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
PlaylistItems.Add(MediaItem)
Next
Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
Dim SoapMapping As Xml.Serialization.XmlTypeMapping = _
(New Xml.Serialization.SoapReflectionImporter).ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
Dim Serializer As New Xml.Serialization.XmlSerializer(SoapMapping)
Using sw As New StreamWriter(Filename)
Serializer.Serialize(sw, PlayList)
End Using
End Sub[/code]
With this class to hold the playlist for serialization
<pre class="prettyprint lang-vb" style=" <Serializable()>
Public Class AvbMediaPlayerPlaylist
Public PlaylistMediaItems As List(Of MyVideo)
Sub New(ByVal PlayListItems As List(Of MyVideo))
Me.PlaylistMediaItems = PlayListItems
End Sub
Sub New()
End Sub
End Class[/code]
<br/>
And that class is a list of this object:
<pre class="prettyprint lang-vb" style=" Option Strict On
<Serializable()>
Public Class MyVideo
Private _fileName As String
Private Property _listBoxText As String
Public Property IsYoutubeObject As Boolean = False
Public Property ListBoxText As String
Get
Return _listBoxText
End Get
Set(ByVal value As String)
_listBoxText = value
End Set
End Property
Public Property Filename As String
Get
Return _fileName
End Get
Set(ByVal value As String)
Me._fileName = value
_listBoxText = IO.Path.GetFileNameWithoutExtension(value)
End Set
End Property
Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
Me.Filename = FileName
If Not SkipTitleRequest Then
If Not AlternateTitle = "" Then
If ValidYoutubeURL(FileName) Then
Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
If DisplayText = "" Then
_listBoxText = "Youtube Video"
Else
_listBoxText = DisplayText
End If
End If
End If
Else
If Not AlternateTitle = "" Then
Me._listBoxText = AlternateTitle
End If
End If
If ValidYoutubeURL(FileName) Then
Me.IsYoutubeObject = True
End If
End Sub
Sub New()
End Sub
Public Overrides Function ToString() As String
Return Me.ListBoxText
End Function
Function ValidYoutubeURL(ByVal URL As String) As Boolean
If (URL.IndexOf("www.youtube.com") <> -1) Then Return True
Return False
End Function
End Class[/code]
<br/>
<
If you want something youve never had, you need to do something youve never done.
<br/>
<br/>
Everyone should take the time to mark helpful posts and propose answers!
Answer an interesting question?<br/>
http://social.technet.microsoft.com/wiki/ Create a wiki article about it!<br/>
http://social.technet.microsoft.com/wiki/contents/articles/14665.visual-basic-articles-by-paul-ishak.aspx My Technet Wiki Articles
<br/>
<br/>
View the full article
HResult=-2146233079<br/>
Message=There was an error generating the XML document.<br/>
Source=System.Xml<br/>
StackTrace:<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o, XmlSerializerNamespaces namespaces)<br/>
at System.Xml.Serialization.XmlSerializer.Serialize(TextWriter textWriter, Object o)<br/>
at WindowsApplication1.Form1.SavePlayList(String Filename) in C:UsersRocketShipDesktopF Drive - My FilesOrganized FilesProjectsvidplayerExamplevidplayerExampleForm1.vb:line 403<br/>
at WindowsApplication1.Form1.ToCRDelimitedTextFileToolStripMenuItem_Click(Object sender, EventArgs e) in C:UsersRocketShipDesktopF Drive - My FilesOrganized FilesProjectsvidplayerExamplevidplayerExampleForm1.vb:line 739<br/>
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)<br/>
at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)<br/>
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)<br/>
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)<br/>
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)<br/>
at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)<br/>
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)<br/>
at System.Windows.Forms.Control.WndProc(Message& m)<br/>
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)<br/>
at System.Windows.Forms.ToolStrip.WndProc(Message& m)<br/>
at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)<br/>
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)<br/>
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)<br/>
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)<br/>
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)<br/>
at System.Windows.Forms.Application.Run(ApplicationContext context)<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()<br/>
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)<br/>
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81<br/>
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)<br/>
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)<br/>
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()<br/>
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)<br/>
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)<br/>
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)<br/>
at System.Threading.ThreadHelper.ThreadStart()<br/>
InnerException: System.InvalidOperationException<br/>
HResult=-2146233079<br/>
Message=Token StartElement in state Epilog would result in an invalid XML document.<br/>
Source=System.Xml<br/>
StackTrace:<br/>
at System.Xml.XmlTextWriter.AutoComplete(Token token)<br/>
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteStartElement(String name, String ns, Object o, Boolean writePrefixed, XmlSerializerNamespaces xmlns)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteArray(String name, String ns, Object o, Type type)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElement(String name, String ns, Object o, Type ambientType)<br/>
at System.Xml.Serialization.XmlSerializationWriter.WriteReferencedElements()<br/>
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write4_AvbMediaPlayerPlaylist(Object o)<br/>
InnerException: <br/>
Any ideas?
I have made this serialization sub:
<pre class="prettyprint lang-vb" style=" Sub SavePlayList(ByVal Filename As String)
Dim PlaylistItems As New List(Of MyVideo)
For Each Item In ListBox1.Items
Dim MediaItem As MyVideo = DirectCast(Item, MyVideo)
PlaylistItems.Add(MediaItem)
Next
Dim PlayList As New AvbMediaPlayerPlaylist(PlaylistItems)
Dim SoapMapping As Xml.Serialization.XmlTypeMapping = _
(New Xml.Serialization.SoapReflectionImporter).ImportTypeMapping(GetType(AvbMediaPlayerPlaylist))
Dim Serializer As New Xml.Serialization.XmlSerializer(SoapMapping)
Using sw As New StreamWriter(Filename)
Serializer.Serialize(sw, PlayList)
End Using
End Sub[/code]
With this class to hold the playlist for serialization
<pre class="prettyprint lang-vb" style=" <Serializable()>
Public Class AvbMediaPlayerPlaylist
Public PlaylistMediaItems As List(Of MyVideo)
Sub New(ByVal PlayListItems As List(Of MyVideo))
Me.PlaylistMediaItems = PlayListItems
End Sub
Sub New()
End Sub
End Class[/code]
<br/>
And that class is a list of this object:
<pre class="prettyprint lang-vb" style=" Option Strict On
<Serializable()>
Public Class MyVideo
Private _fileName As String
Private Property _listBoxText As String
Public Property IsYoutubeObject As Boolean = False
Public Property ListBoxText As String
Get
Return _listBoxText
End Get
Set(ByVal value As String)
_listBoxText = value
End Set
End Property
Public Property Filename As String
Get
Return _fileName
End Get
Set(ByVal value As String)
Me._fileName = value
_listBoxText = IO.Path.GetFileNameWithoutExtension(value)
End Set
End Property
Sub New(ByVal FileName As String, Optional ByVal SkipTitleRequest As Boolean = True, Optional ByVal AlternateTitle As String = "")
Me.Filename = FileName
If Not SkipTitleRequest Then
If Not AlternateTitle = "" Then
If ValidYoutubeURL(FileName) Then
Dim DisplayText As String = InputBox("Please enter a title for this youtube video.", "Enter media title.", "Youtube Video")
If DisplayText = "" Then
_listBoxText = "Youtube Video"
Else
_listBoxText = DisplayText
End If
End If
End If
Else
If Not AlternateTitle = "" Then
Me._listBoxText = AlternateTitle
End If
End If
If ValidYoutubeURL(FileName) Then
Me.IsYoutubeObject = True
End If
End Sub
Sub New()
End Sub
Public Overrides Function ToString() As String
Return Me.ListBoxText
End Function
Function ValidYoutubeURL(ByVal URL As String) As Boolean
If (URL.IndexOf("www.youtube.com") <> -1) Then Return True
Return False
End Function
End Class[/code]
<br/>
<
If you want something youve never had, you need to do something youve never done.
<br/>
<br/>
Everyone should take the time to mark helpful posts and propose answers!
Answer an interesting question?<br/>
http://social.technet.microsoft.com/wiki/ Create a wiki article about it!<br/>
http://social.technet.microsoft.com/wiki/contents/articles/14665.visual-basic-articles-by-paul-ishak.aspx My Technet Wiki Articles
<br/>
<br/>
View the full article