来自另一个程序集的GetType

编程入门 行业动态 更新时间:2024-10-27 19:21:22
本文介绍了来自另一个程序集的GetType的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

Hi 我的解决方案有多个项目。 project1,project2,project3等.Project1有一个目录和一个文本文件。我将这个project1引用到project3。现在我正试图从project3获取文件。但我无法访问。返回null .. 我的代码是

var loadAssembly = Assembly.LoadFrom( Test.Module.dll); rep.LoadLayout(loadAssembly.GetType()。Assembly.GetManifestResourceStream( Test.Module.EmbeddedFiles。 + reportName + .txt));

如何访问文件

解决方案

Hi Sencsk, 您使用的代码似乎是正确的。您应该检查是否可以加载嵌入式资源,还要检查资源名称是否与您尝试加载它的名称相同。如果存在偏差,则在尝试加载资源时将返回 null 。

var loadAssembly = Assembly.LoadFrom( Test.Module.dll); string [] names = loadAssembly.GetType()。Assembly.GetManifestResourceNames();

迭代名称,看看有什么不同。 希望这会有所帮助:)

rep.LoadLayout(Assembly.LoadFrom( Test.Module.dll )。ManifestModule.Assembly.GetManifestResourceStream( Test.Module.EmbeddedFiles。 + reportName + .txt));

Hi My solution have multiple projects. project1,project2,project3 etc.. Project1 have one directory with one text file. i referenced this project1 to project3. Now i'm trying to get the file from project3. but i cant access. its return null.. My code is

var loadAssembly = Assembly.LoadFrom("Test.Module.dll"); rep.LoadLayout(loadAssembly.GetType().Assembly.GetManifestResourceStream( "Test.Module.EmbeddedFiles." + reportName + ".txt"));

How can i access the file

解决方案

Hi Sencsk, The code you're using seems to be correct. You should check if you can load the embedded resource and also check if the name of the resource is the identical to the name you're trying to use to load it. If there is a deviation, it will return null when you tried to load the resource.

var loadAssembly = Assembly.LoadFrom("Test.Module.dll"); string[] names = loadAssembly.GetType().Assembly.GetManifestResourceNames();

iterate through names and see what differs. Hope this helps :)

rep.LoadLayout(Assembly.LoadFrom("Test.Module.dll").ManifestModule.Assembly.GetManifestResourceStream( "Test.Module.EmbeddedFiles." + reportName + ".txt"));

更多推荐

来自另一个程序集的GetType

本文发布于:2023-11-13 11:51:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1584287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   GetType

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!