我怎么可以检索嵌入XML资源? [英] How can I retrieve an embedded xml resource?
问题描述
我通过使用访问Visual Studio中的项目属性,然后添加资源的XML文件作为嵌入资源在我的类库|添加资源|添加现有文件...
我试图访问使用以下code中的文件,但我不断收到一个空引用返回。任何人有什么想法?
VAR路径=使用Server.Mappath(〜/斌/ MyAssembly.dll程序);
VAR总成= Assembly.LoadFile(路径);
VAR流= assembly.GetManifestResourceStream(MyNamespace.filename.xml);
借助 MSDN对于GetManifestResourceStream 页面使这注:
该方法返回一个空引用
(在Visual Basic中为Nothing),如果私人
在另一个程序集资源
访问和调用者不具有
性ReflectionPermission与
ReflectionPermissionFlag.MemberAccess
标志。
块引用>你有没有在你的装配标记的资源作为公?
I added an XML file as an embedded resource in my class library by using the accessing the project properties in Visual Studio and then Resources | Add Resource | Add Existing File...
I've tried to access the file using the following code, but I keep getting a null reference returned. Anyone have any ideas?
var path = Server.MapPath("~/bin/MyAssembly.dll"); var assembly = Assembly.LoadFile(path); var stream = assembly.GetManifestResourceStream("MyNamespace.filename.xml");
解决方案The MSDN page for GetManifestResourceStream makes this note:
This method returns a null reference (Nothing in Visual Basic) if a private resource in another assembly is accessed and the caller does not have ReflectionPermission with the ReflectionPermissionFlag.MemberAccess flag.
Have you marked the resource as "public" in your assembly?
这篇关于我怎么可以检索嵌入XML资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!