using System; static class Program { static int Main() { DocumentForm browseForm = new DocumentForm (); if (browseForm.DoInit () != 248) return 1; var domain = AppDomain.CreateDomain ("foo"); var engine = Engine.CreateRemote (domain); if (engine.GetDomainName () != "foo") return 2; return 0; } } public abstract class EntityBase { } public class GenEntity : EntityBase { } class DocumentForm { internal int DoInit() { var g = new Grid1>(123); var g2 = new Grid2>(123); return g.num + g2.num; } } public class Grid1 : MarshalByRefObject { public int num; public Grid1 (int i) { num = i + 1; } } public class Grid2 : MarshalByRefObject where TEntity : EntityBase, new() { public int num; public Grid2 (int i) { num = i + 1; } } public class Engine : MarshalByRefObject { public Engine () { } public string GetDomainName () { return AppDomain.CurrentDomain.FriendlyName; } public string GetDomainName () { return AppDomain.CurrentDomain.FriendlyName; } public static Engine CreateRemote (AppDomain domain) { return (Engine) domain.CreateInstanceAndUnwrap ( typeof (Engine).Assembly.FullName, typeof (Engine).FullName); } }