.NET Framework Bookmark and Share   
 index > .NET Remoting and Runtime Serialization > Regarding Non-Serialization of a Delegate
 

Regarding Non-Serialization of a Delegate

Hi,

I am having a problem with making a delegate non-serializable. Since, if a class is made serializable then all its members also become serializable. I am having a delegate as defined below. My requirement is to make this delegate non-serializable. But I am not able to find any proper attribute using which I can make this kind of delegate non-serializable.

[Serializable]
  public class SerializableClass
  {
      public delegate void SampleEventDelegate (int Val); 

  }

I know if the delegate is of System.EventHandler type then it can be made non-serializable using [NonSerialized] attribute. But when I try same on a delegate as defined above, it does not works.

If anybody knows how to make such delegates non serializable, please let me know.

Thanks

Regards

Junaid

Syed Junaid

Apply the attribute NonSerlizable to it and make it private.

[Serializable]
  public class SerializableClass
  {

[NonSerliazable]
      private delegate void SampleEventDelegate (int Val); 

  }

Matthijs Krempel

Actually this works as expected. The attribute is applied to fields. So if you pass an object over the wire, that field will be null on the server:

[Serializable]

public class SerializableClass

{

public SerializableClass()

{

objDelegate = Test;

}

private delegate void SampleEventDelegate(int Val);

[NonSerialized]

SampleEventDelegate objDelegate;

void Test(int Val)

{

}

}

Lucian Bargaoanu

You can use google to search for other answers

Custom Search

More Threads

• deserializing without loading assembly
• WCF message logging
• MSDiscoCodeGenerator failing to import WebService/Schema, throwing System.Exception
• .NET Remote - SecurityException
• Inherit MarshallByRefObject and Control?
• Is this possible?
• Permissions
• A way to redirect remote object method call to another server
• Design Question
• BinaryFormatter Problem (C#) - Please Help!