Serializationexception even with [field:NonSerialized]
<p>I have an IPC-Server running with some really simply interface which is working quite ok for now. The interface itself is really simple and only consists of 4 methods. (RemoteCall Method is SingleTone):
<code>
    [Serializable]
    public class NetworkHook : MarshalByRefObject
    {
        public void onIsInstalled(int pid, MessageDirection direction)
        {
        }</p>

<pre><code>    public void onDataRecieved(int pid, MessageDirection direction, byte[][] data)
    {
    }

    public void onException(int pid, MessageDirection direction, Exception exception)
    {
    }

    public void onPing(int pid, MessageDirection direction)
    {
    }
}
</code></pre>

<p></code>
Troubles begun when I started to add events to this class (so any part of the server can subscribe to incoming messages, the remote calling method is SingleTone to keep the eventlisteners). 
As the NetworkHook is serializable I started to add [field: NonSerialzied] tags to my events. That should be fine as I don't need the clients to be aware of the event-listeners (or don't them want to be at all) so loosing them is ok:
<code></p>

<pre><code>    [field: NonSerialized]
    public event EventHandler&lt;InstalledEventArgs&gt; Test;
</code></pre>

<p></code>
Anyway I still got this error and tried another approach with a custom eventhandler this time:
<code></p>

<p>public delegate void HookInstalledEventHandler(object sender, HookInstalledEventArgs args);</p>

<p>[field: NonSerialized]
public event HookInstalledEventHandler Test;</p>

<p></code>
And again - i still get the exception when adding listeners to the event. So i tried to override the serialization method of the NetworkHook-Class:</p>

<p><code>
public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
{ </p>

<p>}</p>

<p></code>
As I don't have any variables I need to save this is pretty simple. But again - I get an exception.
So now I run out of ideas what I could do prevent this exception, or what do I do wrong here (making the events static is a choice I really don't want to do)?</p>

<p>The exception I get:</p>

<p><code></p>

<p>System.Runtime.Serialization.SerializationException wurde nicht behandelt.
  Message="Der Typ \"SimpleHookGUI.CommandLineReporter\" in Assembly \"SimpleHookGUI, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null\" ist nicht als serialisierbar gekennzeichnet."
  Source="mscorlib"
  StackTrace:
    Server stack trace: 
       bei System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers(RuntimeType type)
       bei System.Runtime.Serialization.FormatterServices.GetSerializableMembers(Type type, StreamingContext context)
       bei System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo()
       bei System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context, SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter, ObjectWriter objectWriter)
       bei System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write(WriteObjectInfo objectInfo, NameInfo memberNameInfo, NameInfo typeNameInfo)
       bei System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(Object graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)
       bei System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize(Stream serializationStream, Object graph, Header[] headers, Boolean fCheck)
       bei System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SerializeMessage(IMessage msg, ITransportHeaders&amp; headers, Stream&amp; stream)
       bei System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMessage(IMessage msg)
    Exception rethrown at [0]: 
       bei System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       bei System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
       bei HookManager.NetworkObserver.NetworkHook.add_Test(HookInstalledEventHandler value)
       bei SimpleHookGUI.Program.Main() in xxx\Program.cs:Zeile 24.
       bei System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       bei System.Threading.ThreadHelper.ThreadStart()
  InnerException: </p>

<p><code></p>

<p>I tried this for the first answer:</p>

<p></p>

<pre>    [field: NonSerialized]
    private event EventHandler&lt;HookInstalledEventArgs&gt; test;

    public event EventHandler&lt;HookInstalledEventArgs&gt; Test
    {
        add { this.test = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Combine(this.test, value); }
        remove { this.test = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Remove(this.test, value); }
    } 
</code></pre>

<p></code></p>
