System.Reflection.Assembly.GetEntryAssembly () is null when called from a web application

I am developing a web application in Visual Studio 2010 with a target structure of 3.5 I am using a dll (developed by another team) in which I get an error message for the following code:

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

i checked and found that System.Reflection.Assembly.GetEntryAssembly () returned null, also searched about it and found in msdn that GetEntryAssembly () could return null when it was called from any unmanaged code.

When I call from my web application, it returns null, and when I call from any Windows application, it works fine, i.e. it gets the name of the record assembly (the assembly from which the execution was started). Why does it return null in a web application? I do not understand. I also tried changing the output type of my web project to Class Library, from the project properties in visual studio, but the drop-down list for the output type is disabled and I cannot change the output type of the project. Please help me if any solutions exist for this problem.

early

Amit Shahani

+4
source share
1 answer

It is controlled by the ASP.Net host process. The answer is no. Therefore, the result of GetEntryAssembly in your web application is null.

The decision depends on what your third-party assembly is trying to do and why it calls GetEntryAssembly .

You can create an executable file to place the assembly and run it in a separate process, then the call will return your executable assembly. However, this may not be the best course of action, it depends on what you want to achieve as a whole.

+3
source

All Articles