You should have seen through that

Take this simple bit of C# and execute it. What happens?

  class Handler
public Assembly TypeResolve(object sender, ResolveEventArgs args)
return null;

  static void Main(string[] args)
AppDomain myDomain = AppDomain.CreateDomain("myDomain", null, AppDomain.CurrentDomain.BaseDirectory, "", false);
Handler handler = new Handler();
   myDomain.TypeResolve += new ResolveEventHandler(handler.TypeResolve);

The answer becomes obvious if you add the line
after the creation of the AppDomain. 

The delegate that is passed into the event handler needs to be remoted, and there will be serialization exception when marshaling the instance of Handler as it is not attributed as Serializable. When a colleague came up to me and said he had an event handler that worked when the handler method was static, but not when the handler was an instance method, I was sceptical, but he was proved right in the end.

This entry was posted in Computers and Internet. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s