gpt4 book ai didi

c# - 无法使用 GetManifestResourceStream() 加载嵌入式资源

转载 作者:IT王子 更新时间:2023-10-29 04:46:54 25 4
gpt4 key购买 nike

我正在使用/linkres: 编译器参数嵌入一个二进制文件,但是当我尝试加载它时:

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)

这里有什么问题?

最佳答案

1 - 文件的构建操作应该是嵌入式资源。
2 - 你不能只指定资源名称。您必须在资源名称之前指定整个程序集名称

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

关于c# - 无法使用 GetManifestResourceStream() 加载嵌入式资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16731991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com