Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1004
  • Last Modified:

C# Serialization and Events

I have a project that raises some events. However, I get a serialization error when I run my application from an external test project.

I have searched for an answer on how to get .NET to not serialize my events and tried the [field:NonSerialized] attribute. However, this still does not work and .NET gives me a warning saying that the field keyword is not valid in this location.

How can I get my events in this class to not be serialized because as of right now, I cannot use this class in my application because when I handle the events from my windows form, I get an error telling me that System.Windows.Forms.Form is not marked as serializable.

Does anyone know how to resolve this issue?

Here is my code:

//[field:NonSerialized] gives me a warning -- 'field' is not valid attribute location for this declaration. Valid attribute locations for this declaration are 'type, return'. All Attributes in this block will be ignored.
public delegate void Delegate_EventHandler_Load(object EventRaiser, TWDataLoadEventArgs EventArgs); 
 
//[field:NonSerialized] gives me an error -- 'field' is not a valid attribute for this declaration. Valid attribute locations for this declaration are 'event'. All attributes in this block will be ignored.
public event Delegate_EventHandler_Load OnLoad
{
    add
     {
         lock (ThreadLock_Event_Load)
         {
             if (m_EventHandlerListObj != null)
             {
                 m_EventHandlerListObj.AddHandler(ThreadLock_Event_Connect, value);
             }
         }
   remove   
   {
        if (m_EventHandlerListObj != null)
       {
           m_EventHandlerListObj.RemoveHandler(ThreadLock_Event_ErrorRaised, value);
       }
  }
}

Open in new window

0
soulaco
Asked:
soulaco
1 Solution
 
vo1dCommented:
do you mean the serialization by the designer?
0
 
Jens FiedererCommented:
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now