Question

I have an ObjectDataSource declared like this:

<asp:ObjectDataSource ID="PaymentsDataSource"
                      runat="server"
                      DataObjectTypeName="Payment"
                      TypeName="PaymentAdapter"
                      SelectMethod="GetPayments">
    <SelectParameters>
        <asp:ControlParameter ControlID="StartDate"
                              PropertyName="Text"
                              Name="startDate"
                              Type="DateTime" />
        <asp:ControlParameter ControlID="EndDate"
                              PropertyName="Text"
                              Name="endDate"
                              Type="DateTime" />
        <asp:ControlParameter ControlID="LocationCodes"
                              PropertyName="Items"
                              Name="selectedLocationCodes"
                              Type="Object" />
    </SelectParameters>
</asp:ObjectDataSource>

The control is question is LocationCodes declared like this:

<select id="LocationCodes"
        disabled="disabled"
        runat="server"
        class="chzn-container"
        multiple=""
        data-placeholder="Choose a Location Code(s)"
        style="width: 100%;"
        data-class="span10">
</select>

The server-side Select method on the adapter is defined like this:

[DataObjectMethod(DataObjectMethodType.Select, true)]
public List<Payment> GetPayments(
    DateTime startDate,
    DateTime endDate,
    object selectedLocationCodes)
{
}

Now, even though the ListItemCollection is successfully passed into the Select method and the code in the Select method can process without error, the following error is still being thrown passively in Application_Error. Is there a way to ignore this error?

11/15/2012 13:37:49 168 (Machine=, App=34a846f1, Project=null, Dept=null, Thread=007, TraceLevel=1)
    Exception Source: mscorlib
    Exception Type: System.Runtime.Serialization.SerializationException
    Exception Message: Type 'System.Web.UI.WebControls.ListItemCollection' in Assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.
Was it helpful?

Solution

Okay, so the way I solved this was by turning ViewState off on the ObjectDataSource element by adding this ViewStateMode="Disabled".

OTHER TIPS

The problem is that you cannot serialize an Object. If you were to change "object selectedLocationCodes" to some kind of predefined class then there should be no problem. In order for an object to be serialized it basically needs to be broken down into XML and that means it needs to know what type of data each field is. Object is not specific enough description because it can be anything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top