Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

C# Serialization and Events

Posted on 2009-07-15
2
Medium Priority
?
997 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1500 total points
ID: 24869636
0

Featured Post

Automating Terraform w Jenkins & AWS CodeCommit

How to configure Jenkins and CodeCommit to allow users to easily create and destroy infrastructure using Terraform code.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

722 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