[Mono-list] Serializable object with Non-Serializable Fields --> SerializationException

Robert Jordan robertj at gmx.net
Wed Jun 2 08:46:07 EDT 2010


Hey,

On 02.06.2010 13:51, Jacek Rużyczka wrote:
> Hi folks,
>
> for my .NET remoting app, I am developing a class, which is gonna fetch some
> data from an RDBMS (by using DataSet objects) and make a report out of it. Of
> course, the class needs to be serializable, so it carries the [Serializable]
> attribute.
>
> But: For the database access, it needs to use ADO.NET classes like
> IDataAdapter and DataSet...and these classes are NOT serializable. As you can

DataSet is actually serializable.

> see from my source-code (DBConnectionHandler is a home-brewn (serializable)
> class doing the database connection work for me), the corresponding variables
> are defined within the Start() method, so that they are no instance fields.
>

This "DBConnectionHandler" is most likely the culprit:

 > 		public DBConnectionHandler BackendConnectionHandler {
 > 			set {
 > 				this.handler = value;
 > 			}
 > 		}

Where are you setting this property? How is DBConnectionHandler
implemented.


> 	[Serializable]
> 	public class PrintReceipt : MarshalByRefObject, IBatchJob

Marking a class as [Serializable] and inheriting from MarshalByRefObject 
at the same time is usually a sign that
you've got remoting wrong.

A class is either a MarshalByRefObject and it does not
leave its AppDomain or [Serializable] which means that
it will leave the AppDomain in its serialization form.

Since MarshalByRefObject takes precedence over [Serializable],
your PrintReceipt is actually marshaled by reference.
In this case, [NonSerialized] is not taken into account at
all.

Robert



More information about the Mono-list mailing list