Error Serializing a Wrapped SortedList

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil Galey

    Error Serializing a Wrapped SortedList

    I'm using VB.NET 2002 on Windows 2000 Pro and am having trouble serializing a SortedList.

    This is my class:
    <Serializable() Public Class clsGoodFiles
    Inherits SortedList
    Public Sub New()
    MyBase.New()
    End Sub
    End Class

    This is my calling code:

    Dim xw As New Xml.XmlTextWrit er(Path.Combine (Application.St artupPath, "GoodFiles.xml" ), System.Text.Enc oding.UTF8)
    Dim xs As New Xml.Serializati on.XmlSerialize r(GetType(clsGo odFiles)) <=== ERROR LINE
    Dim obj As New clsGoodFiles()
    obj.Add("ABC.TI F", "A")
    xs.Serialize(xw , obj)
    xw.Close()
    xw = Nothing
    xs = Nothing
    GC.Collect()

    When it gets to the line indicated as ERROR LINE, it generates the following error:

    An unhandled exception of type 'System.Invalid OperationExcept ion' occurred in system.xml.dll
    Additional information: There was an error reflecting 'WindowsApplica tion22.clsGoodF iles'.

    This same technique works fine if I inherit an ArrayList. But ArrayList and SortedList both show Serializable in the documentation. Is there a way to get the serialization of the SortedList to work? Thanks.

    Phil

  • Martin Honnen

    #2
    Re: Error Serializing a Wrapped SortedList

    Phil Galey wrote:
    This same technique works fine if I inherit an ArrayList. But ArrayList
    and SortedList both show Serializable in the documentation. Is there a
    way to get the serialization of the SortedList to work?

    I don't think so, when I try your code with VS 2003 then I get a more
    specific error message:

    Unhandled Exception: System.NotSuppo rtedException: The type
    ConsoleApplicat ion35
    ..Module1+clsGo odFiles is not supported because it implements IDictionary.

    So _XML serialization_ of that type is not supported. ArrayList does not
    implement the interface IDictionary so it is different. And the
    Serializable attribute refers to binary serialization, not XML
    serialization.

    --

    Martin Honnen --- MVP XML

    Comment

    • Phil Galey

      #3
      Re: Error Serializing a Wrapped SortedList

      Ok thanks, Martin.

      Phil

      "Martin Honnen" <mahotrash@yaho o.dewrote in message
      news:u99sQy3LJH A.1304@TK2MSFTN GP02.phx.gbl...
      Phil Galey wrote:
      >
      This same technique works fine if I inherit an ArrayList. But ArrayList
      and SortedList both show Serializable in the documentation. Is there a
      way to get the serialization of the SortedList to work?
      >
      >
      I don't think so, when I try your code with VS 2003 then I get a more
      specific error message:
      >
      Unhandled Exception: System.NotSuppo rtedException: The type
      ConsoleApplicat ion35
      .Module1+clsGoo dFiles is not supported because it implements IDictionary.
      >
      So _XML serialization_ of that type is not supported. ArrayList does not
      implement the interface IDictionary so it is different. And the
      Serializable attribute refers to binary serialization, not XML
      serialization.
      >
      --
      >
      Martin Honnen --- MVP XML
      http://JavaScript.FAQTs.com/

      Comment

      Working...