Avoid Implementing ISerializable when Inheriting

J

jehugaleahsa

I have a base class for all of my data objects, called DataObject.

The DataObject class has no fields, just methods.

I have serializable derived classes, like Customer, that is looks like
this:

[Serializable]
public class Customer : DataObject
{
/* Uses default ctor */
}

However, every time I try to serialize, I get an exception saying that
DataObject can't be serialized.

I marked it with the Serializable attribute but to no affect.

It looks like .NET wants me to implement ISerializable. But if I do
that, each of my derived classes has to do a lot more work (like
provide a new constructor).

Is there a way to make this work without altering every one of my
derived classes?
 
J

jehugaleahsa

I have a base class for all of my data objects, called DataObject.

The DataObject class has no fields, just methods.

I have serializable derived classes, like Customer, that is looks like
this:

[Serializable]
public class Customer : DataObject
{
    /* Uses default ctor */

}

However, every time I try to serialize, I get an exception saying that
DataObject can't be serialized.

I marked it with the Serializable attribute but to no affect.

It looks like .NET wants me to implement ISerializable. But if I do
that, each of my derived classes has to do a lot more work (like
provide a new constructor).

Is there a way to make this work without altering every one of my
derived classes?

Um. Nevermind. It would appear that my testing tool was caching my
DLLs. It just suddenly started working. I was starting to think I was
going crazy.
 
J

jehugaleahsa

I have a base class for all of my data objects, called DataObject.
The DataObject class has no fields, just methods.
I have serializable derived classes, like Customer, that is looks like
this:
[Serializable]
public class Customer : DataObject
{
    /* Uses default ctor */

However, every time I try to serialize, I get an exception saying that
DataObject can't be serialized.
I marked it with the Serializable attribute but to no affect.
It looks like .NET wants me to implement ISerializable. But if I do
that, each of my derived classes has to do a lot more work (like
provide a new constructor).
Is there a way to make this work without altering every one of my
derived classes?

Um. Nevermind. It would appear that my testing tool was caching my
DLLs. It just suddenly started working. I was starting to think I was
going crazy.- Hide quoted text -

- Show quoted text -

It might have something to do with my testing environment (MS'
tester). It appears that if I Debug my tests serialization works. If I
Run my tests they do not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top