none
Get entry assembly in Office Add-In using VSTO RRS feed

  • Question

  • Hi there!

    I'm currently working on a logging infrastructure within a larger framework. Retrieving and logging the name of running application should be part of this. For common Windows Forms applications, I can obtain this information using Assembly.GetEntryAssembly(), which works fine. Some other member of the development department is now building an Office add-in for Word using VSTO and wants to use the logging infrastructure, too. But calling GetEntryAssembly() from the add-in returns null. I already tried searching for a solution, but the only answer I found was trying to use either GetCallingAssembly() or GetExecutingAssembly(). But GetCallingAssembly() only returns the assembly of the logging infrastructure because of the call stack and GetExecutingAssembly() only returns the assembly in that the currently executing code resides - that again is the assembly of the logging infrastructure.

    So my question is, how is it possible to get the entry assembly when it is called from within Office?

    Thanks for your help!
    Stefan


    Greetings, Stefan
    Friday, October 16, 2009 8:00 AM

Answers

  • Does it matter?  You want to log the name of the running program, it is Word.  If you want the name of the add-in assembly, you will have to add a property to your logging class so the add-in can set its name.

    Hans Passant.
    Monday, October 19, 2009 9:07 AM
    Moderator

All replies

  • I haven't written any managed add-ins for Office but the documentation for GetEntryAssembly states that it will return null is the assembly was loaded by unmanaged code, which seems likely for Office. Try examining the MainModule property for the process to see if that will give you the correct file name. You can get the current process by calling Process.GetCurrentProcess.
    Friday, October 16, 2009 10:14 AM
  • Use Process.GetCurrentProcess().

    Hans Passant.
    Friday, October 16, 2009 11:18 AM
    Moderator
  • We tried that, but it returns the path to Word only, but the assembly of the add-in. Any other ideas how to retrieve it?
    Greetings, Stefan
    Monday, October 19, 2009 8:32 AM
  • Does it matter?  You want to log the name of the running program, it is Word.  If you want the name of the add-in assembly, you will have to add a property to your logging class so the add-in can set its name.

    Hans Passant.
    Monday, October 19, 2009 9:07 AM
    Moderator
  • Actually, we wanted the name of the assembly that is invoked by Word, not the Word process itself. But we had a little discussion meanwhile with the outcome that the name of the first invoked/started assembly is less important and the name of the assembly creating a log message should be included in the log. So we changed the source of a log message to the name of the calling assembly (which makes more sense anyway) and only the log file preamble will show the process name.

    But since your recommendation would be a solution to our original idea I will mark it as an answer and consider the problem solved.
    Greetings, Stefan
    Monday, October 19, 2009 12:47 PM