使用DevExpress WinForm消耗资源

时间:2015-05-21 07:43:34

标签: c# dll devexpress assemblies

我正在尝试使用嵌入式资源创建一个exe。一切正常,但如果DevExpress.Utils.dll与.exe不在同一个文件夹中,应用程序崩溃了! 虽然所有dll文件都包含在嵌入式资源中,但我引用了这些文件。 奇怪的是它只是DevExpress.Utils.dll。 未找到的Dll我正在加载:

[STAThread]
  static void Main()
  {
     AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new MyForm());
  }

  private static Assembly CurrentDomainOnAssemblyResolve(object sender, ResolveEventArgs args)
  {
    // the ddls are in a lib folder.
     String resourceName = "MyApplication." + "lib." + new AssemblyName(args.Name).Name + ".dll";

     using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
     {
        if (stream != null)
        {
           Byte[] assemblyData = new Byte[stream.Length];


           stream.Read(assemblyData, 0, assemblyData.Length);


           return Assembly.Load(assemblyData);
        }
     }
     return null;
  }

1 个答案:

答案 0 :(得分:0)

对于遇到此问题的任何人:

DevExpress:" CLR尝试验证Main方法中的代码。由于该方法包含DevExpress类型,因此CLR尝试加载包含此类型的相应程序集并失败,因为.exe文件所在的文件夹中不存在该程序集。"

[STAThread]
static void Main()
{
 AppDomain.CurrentDomain.AssemblyResolve += CurrentDomainOnAssemblyResolve;

  Application.EnableVisualStyles();
  Application.SetCompatibleTextRenderingDefault(false);
  Application.Run(ReturnXtraForm());
}

private static Assembly CurrentDomainOnAssemblyResolve(object sender,   ResolveEventArgs args)
{
// the ddls are in a lib folder.
 String resourceName = "MyApplication." + "lib." + new AssemblyName(args.Name).Name + ".dll";

 using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
 {
    if (stream != null)
    {
       Byte[] assemblyData = new Byte[stream.Length];


       stream.Read(assemblyData, 0, assemblyData.Length);


       return Assembly.Load(assemblyData);
    }
 }
 return null;
}

private static Form ReturnXtraForm() {
      DevExpress.Skins.SkinManager.EnableFormSkins();
      UserLookAndFeel.Default.SetSkinStyle("DevExpress Style");
      return new MyForm();
  }