views:

264

answers:

2

Using SubSonic v2.x: The first issue is the error discussed here:

Server Error in '/......' Application. Cannot serialize member '.....' of type System.Nullable

I'm not sure where to place the code in my DAL from this post to get this working. I tried placing it in one of the partial classes I created for a table, but no go.

Another fix for this is to add:

generateNullableProperties="false"

However this isn't an option in the intelisense in my providers section of my subsonic config for my DAL. (It is supposed to go on the DAL config or the app's config?)

I managed to get around this

[XmlElement(Type = typeof(TblReceiptLineItem))]

to the following code:

public partial class TblReceipt
{
    // no need to override any existing methods or properties as we 
    // are simply adding one

    //[XmlElement]

    // specifying the types of objects to be contained within the arraylist
    [XmlElement(Type = typeof(TblReceiptLineItem))]
    public ArrayList ReceiptLineItemsArr = new ArrayList();
    public string UserPhoneNumber;
    public string UserCardNumber;
}

... and only because I changed a nullable field in TblReceiptLineItem to not nullable.

However, now the error is:

Unable to cast object of type 'System.Collections.ArrayList' to type 'DAL.TblReceiptLineItem'.

So I'm thinking it hasn't even gotten to the Nullable type error yet and not liking the cast.

So what is the best way to serialize an object that contains a collection with 1..* elements of a custom type (that is SubSonic-friendly). And what is the best way to de-serialize this data?

The second (not yet) issue, is I have an object with a collection of objects in one of its members. Do I have to serialized the collection within the object before serializing the entire object, or will the XmlSerializer take care of all of this?

Thank you.

== UPDATE ==

So it looks like the problem was actually solved with my little fix above. I had some other erroneous code that was causing the second error.

However, my code now fully serializes the main object with the array list of objects inside.

So the fix was to add the type before declaration:

[XmlElement(Type = typeof(TblReceiptLineItem))]

However better ways of accomplishing this (or others) are welcome.

+1  A: 
BioBuckyBall
In my table's partial class, I added an ArrayList property. However, what you're saying is that this won't work come time for serialization. So trying to make it an Array - I get this error: "Cannot create an instance of the abstract class or Interface System.Array" .
ElHaix
... however, assigning an instance of XmlElementAttribute should take care of that, no?: [XmlElement(Type = typeof(TblReceiptLineItem))] - before the ArrayList declaration...
ElHaix
A: 

Glad you got it fixed - serializing nullable types crashes and burns in C# 2.0 in general - but if it works, hurrah!

Rob Conery