代码
[STAThread]
static void Main()
{
try
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
//AppDomain.CurrentDomain.Load(Properties.Resources.XXX_Admin);
// 从二进制流加载主程序集(EXE文件)
Assembly assembly = Assembly.Load(Properties.Resources.XXX_Admin);
// 获取程序集的入口方法(main方法)
MethodInfo mi = assembly.EntryPoint;
// 调用程序集的入口方法
mi.Invoke(null, null);
}
catch (Exception ex)
{
string msg = ex.Message;
throw;
}
}
/// <summary>
/// 加载主程序集所引用的程序集
/// </summary>
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly assembly = null;
try
{
string dllName = args.Name.Split(',')[0];
if (dllName.StartsWith("XXX.Common"))
{
assembly = Assembly.Load(Properties.Resources.XXX_Common);
}
}
catch (Exception)
{
MessageBox.Show("加载数据集" + args.Name + "时出错!");
}
return assembly;
}
static void Main()
{
try
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
//AppDomain.CurrentDomain.Load(Properties.Resources.XXX_Admin);
// 从二进制流加载主程序集(EXE文件)
Assembly assembly = Assembly.Load(Properties.Resources.XXX_Admin);
// 获取程序集的入口方法(main方法)
MethodInfo mi = assembly.EntryPoint;
// 调用程序集的入口方法
mi.Invoke(null, null);
}
catch (Exception ex)
{
string msg = ex.Message;
throw;
}
}
/// <summary>
/// 加载主程序集所引用的程序集
/// </summary>
static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
Assembly assembly = null;
try
{
string dllName = args.Name.Split(',')[0];
if (dllName.StartsWith("XXX.Common"))
{
assembly = Assembly.Load(Properties.Resources.XXX_Common);
}
}
catch (Exception)
{
MessageBox.Show("加载数据集" + args.Name + "时出错!");
}
return assembly;
}