Never trust GetEntryAssembly

One quick tip-

I was using Assembly.GetEntryAssembly().FullName in my logging infrastructure to get the name of the application assembly. It turns out that the call throws an exception when called in any appdomain other than the default - GetEntyAssembly returns null, and the .Fullname causes the exception. A better solution: Process.GetCurrentProcess().ProcessName. As an added bonus, the GetCurrentProcess also provides a list of loaded modules, each with oodles of properties.

Comments (2)

  1. If you execute code in another app domain using AppDomain.ExecuteAssembly(assemblyFile), it will return ‘assemblyFile’ rather than null. You need to do this if you’re running a windows forms app in a non-default app domain. System.Windows.Forms.Application uses GetEntryAssembly to get information about the application.

  2. Addy Santo says:

    Thanks for the tip… We have all kinds of remoting requirements, but I’ll check if we can use ExecuteAssembly instead of our current AppDomain.CreateInstanceAndUnwrap

Skip to main content