Solved

C# Serialization and Events

Posted on 2009-07-15
2
976 Views
Last Modified: 2013-12-17
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
Comment
Question by:soulaco
2 Comments
 
LVL 11

Expert Comment

by:vo1d
ID: 24869614
do you mean the serialization by the designer?
0
 
LVL 23

Accepted Solution

by:
Jens Fiederer earned 500 total points
ID: 24869636
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now