Assembly.GetExecutingAssembly() 未查找正确的路径

发布于 2024-10-03 07:55:37 字数 365 浏览 0 评论 0原文

读取嵌入的 xml 文件

我正在使用C#

var AssemblyRef = Assembly.GetExecutingAssembly();
TextReader reader = new StreamReader(AssemblyRef.GetManifestResourceStream("Text.xml"));

:它已经工作了一段时间,但开始抛出错误。我跟踪了它正在寻找的路径,它正在 bin 文件夹的根目录中查找 dll,而不是在 Debug 或release 文件夹中。

一旦发布,这很好,但对于本地开发,我无法让我的一项功能发挥作用。

我在编译时将其设置为“调试”。任何帮助都会很棒。

I'm reading an embedded xml file using

C#:

var AssemblyRef = Assembly.GetExecutingAssembly();
TextReader reader = new StreamReader(AssemblyRef.GetManifestResourceStream("Text.xml"));

It has been working for some time, but starting throwing errors. I traced the path that it is looking for and it is looking for the dll in the root of the bin folder and not in the Debug or release folder.

Once it is published this is fine, but for local development I cannot get my one feature to work.

I have it set to Debug when compiling. Any help would be great.

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

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

发布评论

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

评论(2

柠檬心 2024-10-10 07:55:37

您已:

  • 更改程序集名称或
  • 更改命名空间或
  • 将资源移动到项目中的文件夹

You have:

  • Changed Assembly Name OR
  • Changed namespace OR
  • Moved the resource to a folder in the project
油焖大侠 2024-10-10 07:55:37

我把电话改成了这个,一切都很好。

TextReader reader = new StreamReader(Assembly.GetExecutingAssembly().AssemblyRef.GetManifestResourceStream("Text.xml"));

通过一项声明就可以实现这一目标。我不知道为什么。

I changed the call to this and everything is fine.

TextReader reader = new StreamReader(Assembly.GetExecutingAssembly().AssemblyRef.GetManifestResourceStream("Text.xml"));

Making the call one statement made it work. I'm not sure why.

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