با استفاده از App Domain و Remote Method می تونید البته به شرط اینکه که Type کلاسی که Cast شده است در AppDomain فعلی وجود داشته باشد یعنی اسمبلی که برای متد CreateInstanceAndUnwrap اسمبلی برنامه فعلی باشد ویا اسمبلی مورد نظر را در AppDomain جاری نیز بارگذاری کرده باشد.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.Remoting;
namespace MyTestRemote
{
public class MyTestRemote
{
public static void Main(string[] args)
{
AppDomain thisDomain = Thread.GetDomain();
AppDomain newDomain = AppDomain.CreateDomain("NEW_DOMAIN", null, null);
RemoteClass c1 = (RemoteClass)newDomain.CreateInstanceFromAndUnwrap ("YourApp.exe", "MyTestRemote.RemoteClass");
c1.RemoteMethod();
AppDomain.Unload(newDomain);
Console.ReadKey();
}
}
public class RemoteClass : MarshalByRefObject
{
public RemoteClass()
{}
public void RemoteMethod()
{
Console.WriteLine("Remote Method is Running in This Thrad {0} ->", Thread.GetDomain().FriendlyName);
}
}
}