与GetManifestResourceStream()斜面加载嵌入的资源 [英] Cant load embedded resource with GetManifestResourceStream()

查看:243
本文介绍了与GetManifestResourceStream()斜面加载嵌入的资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在嵌入的二进制文件与/ linkres:编译器参数,但是当我尝试与加载它:

I am embedding a binary file with the /linkres: compiler argument, but when i try to load it with:

System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
string[] names = myAssembly.GetManifestResourceNames(); // it is really there by its name "shader.tkb"
Stream myStream = myAssembly.GetManifestResourceStream( names[0] );

这导致了

 Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'shader.tkb' or one of its dependencies. The system cannot find the file specified. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeAssembly.GetResource(RuntimeAssembly assembly, String resourceName, UInt64& length, StackCrawlMarkHandle stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name, StackCrawlMark& stackMark, Boolean skipSecurityCheck)
at System.Reflection.RuntimeAssembly.GetManifestResourceStream(String name)

有什么问题吗?

What is the problem here?

推荐答案

1 - 文件的生成操作应嵌入的资源。
2 - 你不能只指定资源的名称。你必须在资源名前指定整个组件名称

1 - The file's build action should be Embedded Resource.
2 - You can’t just specify the resource name. You have to specify the entire assembly name before the resource name

Assembly assembly = this.GetType().Assembly;
assembly.GetManifestResourceStream(
    assembly.GetName().Name + "." + "SubFolderNameIfAny" + ".shader.tkb");

这篇关于与GetManifestResourceStream()斜面加载嵌入的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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