简体   繁体   English

在引用的程序集中找不到嵌入式资源

[英]Cannot find embedded resource in referenced assembly

I have referenced another project containing a WPF form I want to use. 我已经引用了另一个包含要使用的WPF表单的项目。 This form happens to have a little icon at the top left of it. 该表格的左上方恰好有一个小图标。

In my own VSTO project, I have a button that should call the form. 在我自己的VSTO项目中,我有一个应该调用表单的按钮。

At runtime, clicking the button gives me an error saying that it cannot get the resource '$this.Icon', which is an embedded resource of the WPF form I am referencing. 在运行时,单击按钮给我一个错误,提示它无法获取资源'$ this.Icon',这是我正在引用的WPF表单的嵌入式资源。

I did a little test, created another Outlook plugin that calls the same form at startup. 我做了一点测试,创建了另一个Outlook插件,该插件在启动时会调用相同的表单。 The form loads fine without errors. 表单加载正常,没有错误。

Any ideas on what could be causing this; 关于可能造成这种情况的任何想法; going through the code for hours yields nothing :( 经过几个小时的代码不会产生任何结果:(

EDIT : sorry, it's a winform, not the newer WPF 编辑:对不起,这是一个winform,而不是较新的WPF

Two things to check: 检查两件事:

  1. Make sure the Build Action property on the icon is set to Embedded Resource. 确保图标上的“构建操作”属性设置为“嵌入式资源”。

  2. Are you using the fully qualified name of the resource? 您使用的是资源的全限定名吗? This bit of code will dump out the names of your assembly resources: 这部分代码将转储您的程序集资源的名称:

     Assembly _assembly; _assembly = Assembly.GetExecutingAssembly(); string[] names = _assembly.GetManifestResourceNames(); foreach (string name in names) System.Console.WriteLine(name); 

On a project I found after running this the console showed me a few resource namespaces, but no embedded objects! 在运行此命令后我发现的一个项目中,控制台向我显示了一些资源名称空间,但没有嵌入式对象! Even had Image1.bmp clearly in my Solution Explorer, and in my Project properties, Resources tab, it never showed up. 甚至在我的解决方案资源管理器中也有Image1.bmp,并且在我的项目属性的“资源”选项卡中也从未显示过。 The trick in getting this to work is to make certain that Image1.bmp was set to Embedded Resource in the Properties window. 使此功能起作用的技巧是确保在“属性”窗口中将Image1.bmp设置为Embedded Resource。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM