Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

I have serveral classes derived from Form and UserControl. These classes get their data from a set of classes I wrote which are declared as being serialized.

 

When I try and save the data for the serialized classes, I get an error saying one of my UserControl derived classes is not marked as serializable (see attached for message). Indeed, the class that the dialog is identifying is not marked as serializable, and I dont want it to be serialized.

 

I figured out that my use of an event object in my data class is causing the problem. If I comment out the event declaration below, my application works. So my data class is trying to serialize the event object. But if I try and use [NonSerialized] in front of the event declaration, I get a compiler error saying [NonSerialized] is only valid on fields.

 

public delegate void DataChanged( Object source, COSPData data );

 

private event DataChanged m_notifyDataChangedClient;

 

So what can I do to prevent my data class from trying to serialize the object associated with the event? If I cannot mark it as [NonSerialized], then wha else can I do?

 

thanks

Bryan

Edited by bwells
Posted (edited)

Ok. I tried implementing ISerializable. My base class where the problem is with the event has no data, so it is simple to do. But when I run the program, I get an error dialog saying that no constructor to deserialize the object was found. The class in question is a derived class. So it is acting as if that I have to implement the ISerializable interface on all derived classes as well as the base class. Does this seem right? I only want to change the serilaizlation behavior on the base class and I want the derived classes to do the "regular" thing.

 

Can you tell me if I implement the ISerializable interface on a base class, must I also implement this on a derived class too?

 

I have over 20 derived classes and I dont want to implement the ISerializable interface on all of them just because of one event in the base class. Perhaps you have an idea of how I could wrap the event data member so I can have it available to all my derived classes, but yet it is not part of the serialization? The event is designed to be used to notify dependents when the data changes. That is how it got tied into the data classes.

 

I am open to any ideas!

 

 

 

thanks

Bryan

Edited by bwells
Posted

i believe that all derived classes must be declared <Serializable> as well.. i had a similiar issue and i was forced to add this to all my classes to get it to work.

 

it's funny how me and you are having the same troubles at about the same time... good luck

i'm not lazy i'm just resting before i get tired.
Posted

My solution was to move the event out of the base class into a wrapper class. The wrapper class is just a pass through which the base class uses to provide the interface I wanted. By wrapping the event in another class, I was able to use the NonSerialized attribute on the wrapper data member and then everything worked fine.

 

 

Some of this stuff is like poking around in the dark, trying to find your way trhough a maze.

 

Thanks!

Bryan

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...