Databound checkbox serialization error.

Databound checkbox serialization error.

Old forum URL: forums.lhotka.net/forums/t/5490.aspx


jwhook posted on Monday, September 29, 2008

We're attempting to improve the user-behavior on checkboxes by changing databinding to the OnPropertyChanged event, instead of the default.

Doing so, we now get a serialization error when the user actually checks the checkbox. It starts:

System.Runtime.Serialization.SerializationException: Type 'System.Windows.Forms.BindToObject' in Assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.

We're still on version 1.53 of CSLA, which has been recompiled under .NET 2.0. All else is working very well.

Thanks for any input.

- jim

jwhook replied on Tuesday, October 07, 2008

Additional information. Hoping someone can point out if I can serialize, and where to do it.

The offending code producing the quoted error is:

Global.BindField(chkOverwriteTotal, "Checked", m_FixtureCountCollection["6-B"], "NumberOfFixtures", b_Format, b_Parse);

chkOverwriteTotal.DataBindings["Checked"].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

The first line uses some general code of ours for binding controls adapted from Rocky's book. When I added the next line to get instant response on the check box, the serialization error occurs. Note that it occurs at runtime when the user actually clicks on the checkbox.

Once more, a plea for help.

Thanks.

sergeyb replied on Tuesday, October 07, 2008

Are you subscribing to any events for this checkbox on your form, such as CheckedChanged?

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jwhook [mailto:cslanet@lhotka.net]
Sent: Tuesday, October 07, 2008 7:02 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] Databound checkbox serialization error.

 

Additional information. Hoping someone can point out if I can serialize, and where to do it.

The offending code producing the quoted error is:

Global.BindField(chkOverwriteTotal, "Checked", m_FixtureCountCollection["6-B"], "NumberOfFixtures", b_Format, b_Parse);

chkOverwriteTotal.DataBindings["Checked"].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

The first line uses some general code of ours for binding controls adapted from Rocky's book. When I added the next line to get instant response on the check box, the serialization error occurs. Note that it occurs at runtime when the user actually clicks on the checkbox.

Once more, a plea for help.

Thanks.


jwhook replied on Wednesday, October 08, 2008

Yes. But I've tested without subscribing to any events. Same problem.

sergeyb replied on Wednesday, October 08, 2008

Hmmm.  I am afraid I do not have a good idea of why this occurs.  Could there be an issue with custom code you guys have?  Could you try to bind the checkbox manually just to test this theory?

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jwhook [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 08, 2008 12:51 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Databound checkbox serialization error.

 

Yes. But I've tested without subscribing to any events. Same problem.


jwhook replied on Wednesday, October 08, 2008

Hi Sergey.

I'll try to create a simplified version of what we're doing, but from your response, I guess you're saying that, in theory, I should be able to do this kind of thing:

chkOverwriteTotal.DataBindings["Checked"].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

without any problems, if I can get my code right.

As an alternative, I tried forcing the datasource to be updated during the CheckedChange event using the DataBindings[indx].WriteValue() method, but it triggers the same kind of serialization error.

- jim

sergeyb replied on Wednesday, October 08, 2008

You should be able to do something like just to test the theory.   I would recommend disabling CHeckedChanged event for testing as well just to eliminate as many moving parts from test as possible.

 

chkOverwriteTotal.DataBindins.Add(“Checked”, objectOrDataSource, “MyProperty”, null, DataSourceUpdateMode.OnPropertyChanged);

 

Serialization error typically occurs if you are attaching a non-serializable object to your object graph, most commonly via an event.

 

Sergey Barskiy

Principal Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: jwhook [mailto:cslanet@lhotka.net]
Sent: Wednesday, October 08, 2008 2:07 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: RE: Databound checkbox serialization error.

 

Hi Sergey.

I'll try to create a simplified version of what we're doing, but from your response, I guess you're saying that, in theory, I should be able to do this kind of thing:

chkOverwriteTotal.DataBindings["Checked"].DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;

without any problems, if I can get my code right.

As an alternative, I tried forcing the datasource to be updated during the CheckedChange event using the DataBindings[indx].WriteValue() method, but it triggers the same kind of serialization error.

- jim


jwhook replied on Wednesday, October 08, 2008

Sergey.

Thanks for pointing me in the right direction. Turns out that our object (not UI controls) had an event handler for the property that the control was bound to.

Copyright (c) Marimer LLC