Heres the current structure of the code:
EmailServerFactory
|-->Create() :: ExchangeServerClass
EmailServerFactory.Create() will load an appDomain with the ExchangeServerClass.
The ExchangeServerClass makes calls to the MailParserFactory.Parse() method which is in the *same* assembly. And returns the following:
MailParserFactory
|-->Parse(emailAddress) :: IEmail
The client Console application is the following:
IEmailServerFactory emailFactory = EmailServerFactory.Create()
IEmail[] emails = emailFactory.RetrieveMessages(MessageFlags.New)
emails.ForEach(delegate(IEmail email) { Console.WriteLine(email.Subject); })
Since the EmailServerFactory.Create() method is loading an AppDomain behind the scenes and returning the IEmailServerFactory instance one has to be careful of the information being passed back from any functions from a class like that.
Line #3 throws an Exception because you're crossing AppDomain's at that point (trying to access a class that was created in another AppDomain). To remedy this problem I had to mark the classes as Serializable (the classes that implement the IEmail interface)