System.Reflection.Assembly.Get ... [英] System.Reflection.Assembly.Get...

查看:37
本文介绍了System.Reflection.Assembly.Get ...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用目标框架在Visual Studio 2010中开发一个Web应用程序 - 3.5我正在使用一个dll(由另一个团队开发),其中我收到以下代码的错误:



  string  strName = System.Reflection.Assembly.GetEntryAssembly()。GetName()。Name; 





i检查并发现System.Reflection.Assembly.GetEntryAssembly()返回null并且还搜索了那个并找到了在msdn上,当从任何非托管代码调用它时,GetEntryAssembly()可能返回null。



当我从我的Web应用程序调用时,它返回null并且当我从任何Windows应用程序调用,它工作正常,即它获取条目程序集名称(执行已启动的程序集)。为什么它在Web应用程序中返回null?我无法理解。我还尝试将我的Web项目的输出类型从Visual Studio中的项目属性更改为类库,但是输出类型的下拉列表被禁用,我无法更改项目的输出类型。如果这个问题有任何解决方案,请帮帮我。



提前谢谢



Amit Shahani

解决方案

从非托管应用程序加载托管程序集时,GetEntryAssembly方法可以返回null。例如,如果非托管应用程序创建用C#编写的COM组件的实例,则从C#组件调用GetEntryAssembly方法将返回null,因为该进程的入口点是非托管代码而不是托管程序集。

I am developing a web application in visual studio 2010 with target framework - 3.5 I am using a dll (developed by another team) in which i get an error for following code :

string strName = System.Reflection.Assembly.GetEntryAssembly().GetName().Name;



i checked and found that System.Reflection.Assembly.GetEntryAssembly() is returning null and also searched about that and found on msdn that GetEntryAssembly() may return null, when it is called from any unmanaged code.

When I am calling from my web application, it is returning null and when I call from any windows application, it works fine,i.e. it gets the entry assembly name (the assembly from which the execution has started). Why it is returning null in Web application? i can''t understand. I also tried to change the output type of my web project to Class Library, from the project properties in visual studio, but the dropdown for output type, is disabled and i can''t change the output type of the project. Please help me if any solutions exists for this problem.

thanks in advance

Amit Shahani

解决方案

The GetEntryAssembly method can return null when a managed assembly has been loaded from an unmanaged application. For example, if an unmanaged application creates an instance of a COM component written in C#, a call to the GetEntryAssembly method from the C# component returns null, because the entry point for the process was unmanaged code rather than a managed assembly.


这篇关于System.Reflection.Assembly.Get ...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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