Search code examples
.netvb.net.net-2.0xml-serialization

XML-Serializing delegates


I have a class that I want to be serializable but contains a public instance of delegate that, apparently can't be serialized:

<Serializable()> Class A
    Public Delegate Function TestEventHandler(ByVal myObj as CutomObject, _
                                         ByVal myObj2 as CustomObject) as Boolean

    ' does not 'want' to be serialized - cause: no parameterless constructor'
    Public TestDelegate as TestEventHandler
End Class

I used <XmlIgnore()> _ and it helped - i mean the exception is not trowed at this member anymore.

Is there a way to make it serializable however?


Solution

  • Use [XmlIgnore] on the delegate.


    No, there's no way to serialize a delegate. What would it even look like, and what would a platform other than .NET do with it?