来自另一个程序集的GetType [英] GetType from Another assembly

查看:111
本文介绍了来自另一个程序集的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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