111,093
社区成员




byte[] bts = 来自网络的受保护的dll文件(不能保存在本地); //PS:此文件是正确的.NET dll文件
AppDomain domain = AppDomain.CreateDomain("NewDomain");
Assembly asm = domain.Load(bts); //PS:异常,系统找不到指定的文件。
using System;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
class Test
{
public static void Main()
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.AssemblyResolve += new ResolveEventHandler(MyResolver);
InstantiateMyType(currentDomain); // OK!
}
static void InstantiateMyType(AppDomain domain)
{
try
{
// You must supply a valid fully qualified assembly name here.
domain.CreateInstance("Assembly text name, Version, Culture, PublicKeyToken", "MyType");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
// Loads the content of a file to a byte array.
static Assembly MyResolver(object sender, ResolveEventArgs args)
{
AppDomain domain = (AppDomain)sender;
// Once the files are generated, this call is
// actually no longer necessary.
//EmitAssembly(domain);
String strdll = "dll 二进制据的base64代码";
String strpdb = "符号表文件二进制数据base64代码";
byte[] rawAssembly = System.Convert.FromBase64String(strdll);
byte[] rawSymbolStore = System.Convert.FromBase64String(strpdb);
Assembly assembly = domain.Load(rawAssembly, rawSymbolStore);
return assembly;
}
// Creates a dynamic assembly with symbol information
// and saves them to temp.dll and temp.pdb
static void EmitAssembly(AppDomain domain)
{
}
}
dll pdb文件 二进制的base64代码由于回帖字数限制,没发帖,你自己生成吧
用System.Convert.ToBase64String(byte流);
byte[] rawAssembly = 来自网络,因为安全问题文件不在客户端;
if (rawAssembly == null ||
rawAssembly.Length == 0)
return null;
Assembly asm = Assembly.Load(rawAssembly); //正确
AppDomain domain = AppDomain.CreateDomain("new");
asm = domain.Load(asm.GetName()); //异常,因为没有这个文件;