1代码
1.1程序集代码
using System;
using System.Runtime.Remoting;
// c#-程序集-程序集域-程序集端
namespace cxj
{
public class a: MarshalByRefObject
{
public int get(){
return 5;
}
}
}
编译过程
csc /target:module a.cs
csc /target:library /addmodule:a.netmodule /out:a.dll
1.2 调用程序集端代码
using System;
using System.Runtime.Remoting;
// 调用程序集端
namespace cxj
{
class b
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
AppDomain cd2 = AppDomain.CreateDomain("new appDomain");
//cd2.ExecuteAssembly("c.exe");
//ObjectHandle a2 = cd2.CreateInstance("a","cxj.a");
//cd2.ExecuteAssembly("c.dll","");
//a a1 = (a)cd2.Unwrap();
a a1 = (a)cd2.CreateInstanceAndUnwrap("a","cxj.a");
Console.WriteLine("a1.get():"+a1.get());
Console.ReadKey();
}
}
}
编译
csc b.cs /r:a.dll