未能从程序集中加载类型

using System;

namespace Clr.CSharp
{
    public class Worker : MarshalByRefObject
    {
        public void PrintDomain()
        {
            Console.WriteLine("Object is executing in AppDomain : {0}", AppDomain.CurrentDomain.FriendlyName);
        }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            Worker localWorker = new Worker();
            localWorker.PrintDomain();

            AppDomain ad = AppDomain.CreateDomain("New Domain");

            // 这里开始没有添加类的名称空间,就抛出异常,加上就OK了
            Worker remoteWorker =
                (Worker)ad.CreateInstanceAndUnwrap(typeof(Program).Assembly.FullName, "Clr.CSharp.Worker"/*Worker*/);
            remoteWorker.PrintDomain();

            Console.ReadLine();
        }
    }
}

你可能感兴趣的:(C#)