1

I am developing an add-in for excel

In excel i am adding reference to the dll file created and using functions from that

example

Set o = CreateObject("DllName.PublishFile")

here I have added reference to a .tlb file i.e in excel i pressed alt+f11 to goto macros, i clicked on tools, clicked on reference and added the .tlb file by browsing to the path of the file

the location of this file is

C:/Program Files/Project/Bin/Debug

In the code , to get path of app.config i have used

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase

to get the location of dll i.e D:/ProjectName/Bin/Debug

After this, i used installshield to create installer and installed it

Now the location of the dll is C:/Program Files/Project/

Here i have app.config, dll.config etc

After installation, I changed the reference of the dll

i.e i selected .tlb file in C:/Program Files/Project/ instead of the .tlb file located in D:/ProjectName/Bin/Debug. But it is still getting config values from the app.config in Bin/Debug!!

How can i get the values from app.config in dll's folder here?

in short I want the path of the dll/tlb file which i have referred to in the excel macro i.e C:/Program Files/ProjectName But it is taking the app.config present in source code path i.e D:/project/bin/debug

Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
  • Removing VBA tag, Visual Basic for Applications has nothing to do with .NET. – Richard May 06 '15 at 12:44
  • 1
    Question is unclear: do you want the path of the config file (that is answered [here](http://stackoverflow.com/questions/793657/how-to-find-path-of-active-app-config-file)) or the path to the current assembly (in which case you have the code in the question)? – Richard May 06 '15 at 12:47
  • I want the path of the dll/tlb file which i have referred to in the excel i.e C:/Program Files/ProjectName But it is taking the app.config present in source code path i.e D:/project/bin/debug – Vignesh Subramanian May 06 '15 at 12:51
  • This is still unclear. You keep giving directory names as if they are path names. And then you thrown in references to Excel (data content or automation of Excel: also unclear). Remember we know only what you write in the question. – Richard May 06 '15 at 12:59
  • @Richard I have added details to the question – Vignesh Subramanian May 06 '15 at 13:10
  • 1
    That's much better. I suspect each time you build you are registering the new build, thus instantiating that copy from Excel. I would start by checking the COM registration information in the registry. – Richard May 06 '15 at 13:14

1 Answers1

1

GetExecutingAssembly() returns the currently executing assembly (e.g. .exe).

Let's assume you have a type Class1 defined in your DLL, then you could use this to find the path to your library.

string s = System.Reflection.Assembly.GetAssembly(typeof (Class1)).CodeBase;
Greg
  • 1,076
  • 1
  • 9
  • 17
  • `GetExecutingAssembly()` will get the `Assembly` instance for the assembly containing the currently executing code: it will only be the exe for code directly in that exe. (To always get the exe use `Assembly.GetEntryAssembly()`.) – Richard May 06 '15 at 12:58