调用嵌入式资源时应用程序崩溃

发布于 2024-07-26 11:30:42 字数 511 浏览 2 评论 0原文

我正在使用 Visual Basic 2008 Express 编写控制台应用程序。

我将几个文本文件作为资源添加到我的项目中。 具体来说...

  1. 我转到项目的“属性”页面并选择“资源”选项卡。
  2. 我单击“添加资源”下拉列表并选择“添加新文本文件”。
  3. 我输入了一些简单的文本并将文件保存为“Welcome.txt”。
  4. 我构建了整个解决方案。

在我的代码中,我使用 console.writeline(My.Resources.Welcome) 来显示文本。

如果我通过 IDE 运行我的代码,它工作得很好。 如果我运行 /bin/release 文件夹中的 EXE,应用程序就会崩溃。

我的系统日志将错误显示为“System.IO.FileLoadException”。

我尝试将嵌入文本文件的属性设置为“嵌入资源”,但结果是相同的。

有人遇到过这个问题吗? 先感谢您。

I'm writing a console application in Visual Basic 2008 Express.

I added several text files to my project as resources. Specifically...

  1. I went to my project's "Properties" page and selected the "Resources" tab.
  2. I clicked the "Add Resource" dropdown and chose "Add New Text File".
  3. I entered some simple text and saved the file as "Welcome.txt".
  4. I built the entire solution.

In my code, I use console.writeline(My.Resources.Welcome) to display the text.

If I run my code through the IDE, it works fine.
If I run the EXE that's in the /bin/release folder, the app crashes.

My system logs show the error as "System.IO.FileLoadException".

I have tried setting the properties on the embedded text file to "Embedded Resource", but the result is the same.

Has anyone encountered this issue? Thank you in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

魂ガ小子 2024-08-02 11:30:42

将 Welcome.txt 复制到您的 bin\release 文件夹。

或者

要使 Welcome.txt 成为嵌入资源,请右键单击文本文件或位图,然后选择“属性”。

在“属性”对话框中,找到“生成操作”属性。 默认情况下,此属性设置为内容。 单击该属性并将“构建操作”属性更改为“嵌入式资源”。

Copy Welcome.txt to your bin\release folder.

OR

To make Welcome.txt an embedded resource, right-click either the text file or the bitmap, and then select Properties.

In the Properties dialog box, locate the Build Action property. By default, this property is set to Content. Click the property and change the Build Action property to Embedded Resource.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文