XmlSerializationWriter - Specified cast is not valid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tamir Khason

    XmlSerializationWriter - Specified cast is not valid

    Code
    public class RootSerialized
    {
    [XmlElement("Som eCollection")]
    public SomeCollection SomeThings;
    }

    public class SomeCollection: BaseCollection ,ITypedList ,IBindingList
    {
    public SomeCollection( ) : base()
    {
    }
    [XmlElement("Som ething")]
    public Something this[int index]
    {
    get
    {
    return (Something )m_al[index];
    }
    }
    }

    During the serialization

    XmlSerializer s = new XmlSerializer( typeof( RootSerialized ) );

    this this structure return error:
    System.InvalidO perationExcepti on: There was an error generating the XML
    document. ---> System.InvalidC astException: Specified cast is not valid.

    So what is the problem?

    --
    Tamir Khason
    You want dot.NET? Just ask:
    "Please, www.dotnet.us "



  • Kevin Yu [MSFT]

    #2
    RE: XmlSerializatio nWriter - Specified cast is not valid

    Hi Tamir,

    First of all, I would like to confirm my understanding of your issue. From
    your description, I understand that when serializing a class, there is an
    System.InvalidO perationExcepti on, which says "There was an error generating
    the XML document." is generated. If there is any misunderstandin g, please
    feel free to let me know.

    Based on my research, this exception is thrown, because the BaseCollection
    class is not serializable. This class does not implement the ISerializable
    interface and it contains some complex data types. So when the object is
    going to be serialized, the Serialize method doesn't know how to convert
    data in the object, and the exception is thrown.

    HTH.

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."

    Comment

    • Tamir Khason

      #3
      Re: XmlSerializatio nWriter - Specified cast is not valid

      So how can I serialize such structure?

      --
      Tamir Khason
      You want dot.NET? Just ask:
      "Please, www.dotnet.us "


      "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> wrote in message
      news:zkw3faBYEH A.2900@cpmsftng xa06.phx.gbl...[color=blue]
      > Hi Tamir,
      >
      > First of all, I would like to confirm my understanding of your issue. From
      > your description, I understand that when serializing a class, there is an
      > System.InvalidO perationExcepti on, which says "There was an error[/color]
      generating[color=blue]
      > the XML document." is generated. If there is any misunderstandin g, please
      > feel free to let me know.
      >
      > Based on my research, this exception is thrown, because the BaseCollection
      > class is not serializable. This class does not implement the ISerializable
      > interface and it contains some complex data types. So when the object is
      > going to be serialized, the Serialize method doesn't know how to convert
      > data in the object, and the exception is thrown.
      >
      > HTH.
      >
      > Kevin Yu
      > =======
      > "This posting is provided "AS IS" with no warranties, and confers no
      > rights."
      >[/color]


      Comment

      • Simon Smith

        #4
        Re: XmlSerializatio nWriter - Specified cast is not valid

        On 02 Jul 2004 12:21, "Tamir Khason" wrote:[color=blue]
        >So how can I serialize such structure?
        >[/color]

        Implement Iserializable.

        (BTW, if you're going to top post, please don't use the sig dash - '--
        ' - as a lot of newsreaders will cut off quoting text after it, just like
        this answer does.)

        --
        Simon Smith
        simon dot s at ghytred dot com
        www.ghytred.com/NewsLook - NNTP Client for Outlook


        Comment

        • Tamir Khason

          #5
          Re: XmlSerializatio nWriter - Specified cast is not valid

          Outlook Express NewsReader add it automatic. Sorry

          --
          Tamir Khason
          You want dot.NET? Just ask:
          "Please, www.dotnet.us "


          "Simon Smith" <ghytred@commun ity.nospam> wrote in message
          news:ba6fe32be8 3e4c1c8fb17a5b9 ec3b990@ghytred .com...[color=blue]
          > On 02 Jul 2004 12:21, "Tamir Khason" wrote:[color=green]
          > >So how can I serialize such structure?
          > >[/color]
          >
          > Implement Iserializable.
          >
          > (BTW, if you're going to top post, please don't use the sig dash - '--
          > ' - as a lot of newsreaders will cut off quoting text after it, just like
          > this answer does.)
          >
          > --
          > Simon Smith
          > simon dot s at ghytred dot com
          > www.ghytred.com/NewsLook - NNTP Client for Outlook
          >
          >[/color]


          Comment

          • Kevin Yu [MSFT]

            #6
            Re: XmlSerializatio nWriter - Specified cast is not valid

            Hi Tamir,

            To serialize such object, we have to implement ISerialization interface so
            that the serializer will know how to serialize this object.

            Kevin Yu
            =======
            "This posting is provided "AS IS" with no warranties, and confers no
            rights."

            Comment

            • Tamir Khason

              #7
              Re: XmlSerializatio nWriter - Specified cast is not valid

              Thank you for your reply. The issue solved by workaround
              Are there support for this at FW2.0?

              --
              Tamir Khason
              You want dot.NET? Just ask:
              "Please, www.dotnet.us "


              "Kevin Yu [MSFT]" <v-kevy@online.mic rosoft.com> wrote in message
              news:82LwZwjYEH A.2900@cpmsftng xa06.phx.gbl...[color=blue]
              > Hi Tamir,
              >
              > To serialize such object, we have to implement ISerialization interface so
              > that the serializer will know how to serialize this object.
              >
              > Kevin Yu
              > =======
              > "This posting is provided "AS IS" with no warranties, and confers no
              > rights."
              >[/color]


              Comment

              • Kevin Yu [MSFT]

                #8
                Re: XmlSerializatio nWriter - Specified cast is not valid

                Hi Tamir,

                Since .NET framwork 2.0 hasn't been officially release, we are not quite
                sure about the feature of it, because everything might be changed before
                release.

                Kevin Yu
                =======
                "This posting is provided "AS IS" with no warranties, and confers no
                rights."

                Comment

                Working...