嵌入式资源与DevExpress WinForm
本文关键字:WinForm DevExpress 资源 嵌入式 | 更新日期: 2023-09-27 17:50:22
我正在尝试创建一个具有嵌入式资源的exe。一切工作正常,但如果DevExpress.Utils.dll不像.exe一样在同一个文件夹中,应用程序会崩溃!虽然所有dll文件都是作为嵌入式资源包含的,但我引用了这些。奇怪的是,它只是DevExpress.Utils.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;
}
对于遇到这种问题的人:
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();
}