Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After i tried every way to tell the serialization not to serialize my events but they kept on getting serialized I tried it the other way round - give my class NetworkHook what it wants, a serializable class.<br> So I created a new Test class called NetworkListener which is serializable but doesn't serialize the events:</p> <pre><code>[Serializable] public class NetworkListener { private static EventHandler&lt;HookInstalledEventArgs&gt; hookInstalled; public event EventHandler&lt;HookInstalledEventArgs&gt; HookInstalled { add { hookInstalled = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Combine(hookInstalled, value); } remove { hookInstalled = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Remove(hookInstalled, value); } } public void onHookInstalled(Object sender, HookInstalledEventArgs args) { EventHandler&lt;HookInstalledEventArgs&gt; handler = hookInstalled; if (handler != null) { handler(this, args); } } } </code></pre> <p>This class can subscribe to my NetworkHook : MarshalByRefObject without throwing an exception. I think it really is only a dirty workaround with that static event in there which doesn't bahave static to the outside (beside it's just another class to pass events). But I can't make it private only and flag it with [field: NonSerialized()] as it simply looses all callbacks then. So at least I wanted to get rid of that extra class and include that event-workaround in my original class:</p> <pre><code>public class NetworkHook : MarshalByRefObject { private static EventHandler&lt;HookInstalledEventArgs&gt; hookInstalled; public event EventHandler&lt;HookInstalledEventArgs&gt; HookInstalled { add { hookInstalled = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Combine(hookInstalled, value); } remove { hookInstalled = (EventHandler&lt;HookInstalledEventArgs&gt;) Delegate.Remove(hookInstalled, value); } } // .... } </code></pre> <p>And by surprise - I do get my exception again. I some kind a have the feeling the MarshalByRefObject completly bypasses my serialization-commands ... somehow. Well - this is a really bad solution I think and I'll have to rewrite some other classes to fit in this - but for the first time in hours - it works at all. I anyone has a better solution I'd love to give it another try :) As long I'll stick with my original class calling some "event proxy" which does delegate the real events.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload