【发布时间】:2023-03-09 04:17:01
【问题描述】:
我有一个需要将嵌入式 DLL 文件复制到用户目录的 C# WinForms 应用程序。 我无法让我的应用程序识别嵌入式 DLL 文件。有人可以帮忙吗?
系统不断抛出异常参数“eContactAutoCAD.dll 不存在”——显然变量为空。
为了让系统识别嵌入文件,我需要进行哪些更改?
namespace eContact_AutoCAD_Installer
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
const string dllFolder = @"C:\eContact\";
const string dllFile = @"C:\eContact\eContactAutoCAD.dll";
const string EMBED_DLLFILE = "eContact_AutoCAD_Installer.Files.eContactAutoCAD.dll";
/*
---
*/
//Copy DLL to User's "C:/eContact/" folder
private static void copyDLL()
{
if (!Directory.Exists(dllFolder))
{
Directory.CreateDirectory(dllFolder);
}
try
{
using (Stream resource = Assembly.GetExecutingAssembly().GetManifestResourceStream(EMBED_DLLFILE))
{
if (resource == null)
{
throw new ArgumentException("eContactAutoCAD.dll does not exist");
}
using (Stream output = File.OpenWrite(dllFile))
{
resource.CopyTo(output);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
/*
---
*/
}
}
【问题讨论】:
标签: c# embedded-resource