未能从程序集中加载类型“MarshalByRefType”

public static void Marshlling()
  {
   AppDomain adCallingThreadMain = Thread.GetDomain();
   Console.WriteLine("main thread run in {0}", adCallingThreadMain.FriendlyName);
   string exeAssembly = Assembly.GetEntryAssembly().FullName;
  
   Console.WriteLine("main assembly {0}", exeAssembly);

   AppDomain ad2 = AppDomain.CreateDomain("Demo 1", null, null);
   //返回对新的对象的引用
   MarshalByRefType mar = null;

//该句代码开始没加类的命名空间,就报出异常。加上了命名空间就Ok了
   mar = (MarshalByRefType)ad2.CreateInstanceAndUnwrap(exeAssembly, "ConsoleApplication9.MarshalByRefType");
   Console.WriteLine("Type {0}", mar.GetType());
   Console.WriteLine("Is proxy {0}", RemotingServices.IsTransparentProxy(mar));

   
  }

原文地址:https://www.cnblogs.com/363546828/p/2372469.html