serialize class to the viewstate

Discussion in 'ASP .Net' started by Craig Buchanan, Jan 27, 2004.

  1. I am trying to serialize a class called Order to the ViewState. Order has
    one property called LineItems, which is an ArrayList. The ArrayList holds
    instances of a class named LineItem. Bother Order and LineItem are marked
    with the <Serializable> attribute.

    When I attempt to serialize the class using this code:

    Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))

    Dim sw As New StringWriter()

    xs.Serialize(sw, _Order)

    ViewState("LineItems") = sw.ToString()

    On the line xs.Serialize(sw, _Order), I get an error that reads:

    The type LineItem was not expected. Use the XmlInclude or SoapInclude
    attribute to specify types that are not known statically.

    What am I missing?

    Thanks,

    Craig Buchanan
    Craig Buchanan, Jan 27, 2004
    #1
    1. Advertising

  2. Craig Buchanan

    Anon Guest

    You may have to specify what the array list holds with the XmlElement
    attribute.

    I have a list that holds two different types and I had to do apply the
    following to the array list:
    <XmlElement(Type:=GetType(StringCriteriaField)),
    XmlElement(Type:=GetType(IntegerCriteriaField))>


    "Craig Buchanan" <> wrote in message
    news:#...
    > I am trying to serialize a class called Order to the ViewState. Order has
    > one property called LineItems, which is an ArrayList. The ArrayList holds
    > instances of a class named LineItem. Bother Order and LineItem are marked
    > with the <Serializable> attribute.
    >
    > When I attempt to serialize the class using this code:
    >
    > Dim xs As XmlSerializer = New XmlSerializer(GetType(Order))
    >
    > Dim sw As New StringWriter()
    >
    > xs.Serialize(sw, _Order)
    >
    > ViewState("LineItems") = sw.ToString()
    >
    > On the line xs.Serialize(sw, _Order), I get an error that reads:
    >
    > The type LineItem was not expected. Use the XmlInclude or SoapInclude
    > attribute to specify types that are not known statically.
    >
    > What am I missing?
    >
    > Thanks,
    >
    > Craig Buchanan
    >
    >
    Anon, Jan 27, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordz
    Replies:
    3
    Views:
    3,924
    John Oakes
    Jun 7, 2004
  2. Ben Amada

    Can viewstate serialize this class?

    Ben Amada, Oct 16, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    13,116
    john_teague
    Oct 30, 2005
  3. DC
    Replies:
    2
    Views:
    380
  4. Manit Chanthavong

    Serialize a class to viewstate?

    Manit Chanthavong, Jan 7, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    148
    Manit Chanthavong
    Jan 7, 2004
  5. Alex

    Serialize Style to save ViewState

    Alex, Mar 16, 2005, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    322
    Teemu Keiski
    Mar 25, 2005
Loading...

Share This Page