By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,939 Members | 1,547 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,939 IT Pros & Developers. It's quick & easy.

serialize class to the viewstate

P: n/a
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
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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" <so*****@somewhere.com> wrote in message
news:#X*************@TK2MSFTNGP11.phx.gbl...
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

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.