C# 怎么创建不能跨越应用程序域(AppDomain)边界的类型

2020年2月14日21:47:25 评论 845字阅读2分49秒

1.简介

C# 怎么创建不能跨越应用程序域(AppDomain)边界的类型?——请看下文。

2.示例代码

/**
 * 版权所有 编程十万个怎么办(www.tah1986.com)
 */
using System;
using System.Reflection;
using System.Globalization;
class MainClass
{
   public static void ListAssemblies()
   {
      
      
      Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
      foreach (Assembly a in assemblies)
      {
         Console.WriteLine(a.GetName());
      }
   }
   public static void Main()
   {
      ListAssemblies();
      string name1 = "System.Data,Version=2.0.0.0," + "Culture=neutral,PublicKeyToken=b11111111111123";
      Assembly a1 = Assembly.Load(name1);
      AssemblyName name2 = new AssemblyName();
      name2.Name = "System.Xml";
      name2.Version = new Version(2, 0, 0, 0);
      name2.CultureInfo = new CultureInfo("");    
      name2.SetPublicKeyToken(new byte[] {0xb7, 0x7a, 0x5c, 0x56, 0x19, 0x34, 0xe0, 0x89});
      Assembly a2 = Assembly.Load(name2);
      Assembly a3 = Assembly.Load("SomeAssembly");
      Assembly a4 = Assembly.LoadFrom(@"c:\shared\MySharedAssembly.dll");
      ListAssemblies();
   }
}

 
继续阅读
编程十万个怎么办
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: