5

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

leppie
  • 115,091
  • 17
  • 196
  • 297
Amit Shahani
  • 94
  • 3
  • 12

1 Answers1

3

Is the ASP.Net host process managed. The answer is, no. Therefore, the result of GetEntryAssembly in your web app is null.

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

You could create an executable to host the assembly and launch that in a seperate process, then the call would return your executable assembley. However, that may not be the best course of action, it depends on what you want to achieve overall.

Jodrell
  • 34,946
  • 5
  • 87
  • 124
  • should i make another class library project, and call this assembly from that project? – Amit Shahani Feb 14 '13 at 10:51
  • @Amit24, you'd need to start a new process, the entry assembley is the assembly that starts the new process. You need to make a executable assembly and call your thrid party dll from there. Then use `Process.Start` to launch your executable host. http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start(v=vs.110).aspx, this may or may not be the best solution, as I state in my answer. – Jodrell Feb 14 '13 at 11:06
  • Ok now i got it, i need to have an executable assembly, because the process should start from there. Thanks a lot for you help. – Amit Shahani Feb 14 '13 at 11:13