我怎样才能发现"路径"一个嵌入的资源? [英] How can I discover the "path" of an embedded resource?

查看:169
本文介绍了我怎样才能发现"路径"一个嵌入的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我存储PNG作为组装嵌入的资源。从同一个组件内,我有一些code是这样的:

I am storing a PNG as an embedded resource in an assembly. From within the same assembly I have some code like this:

Bitmap image = new Bitmap(typeof(MyClass), "Resources.file.png");

的文件,命名为file.png存储在资源的文件夹(Visual Studio中),并且被标记为嵌入的资源。

The file, named "file.png" is stored in the "Resources" folder (within Visual Studio), and is marked as an embedded resource.

在code失败,出现异常的说法:

The code fails with an exception saying:

资源MyNamespace.Resources.file.png不能在课堂上MyNamespace.MyClass中找到

Resource MyNamespace.Resources.file.png cannot be found in class MyNamespace.MyClass

我有相同的code(在不同的装配,装载不同的资源),它的工作原理。所以我知道该技术是健全的。我的问题是我最终花了很多时间试图找出正确的路径是什么。如果我可以简单查询(如:在调试器)大会找到正确的道路,这将节省我头疼的负荷。

I have identical code (in a different assembly, loading a different resource) which works. So I know the technique is sound. My problem is I end up spending a lot of time trying to figure out what the correct path is. If I could simply query (eg. in the debugger) the assembly to find the correct path, that would save me a load of headaches.

推荐答案

这将让你的所有资源字符串数组:

This will get you a string array of all the resources:

System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();

这篇关于我怎样才能发现"路径"一个嵌入的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆