Class library and config files...again

O

OO

Hi all,

OK loads of posts on here about developers trying to use an app.config
for a dll class library. Of course I would normally say the config
file is down to the app domain of the application calling your class
library: a web app or an exe.

However....in my case, I need to call this class library from vbscript
for some legacy applications and so I do not have an Xml config file.
I am happy to create a class which I use to hold my config logic and
open an Xml file and use the XmlDocument for loading it up and working
through it.

But I really want to call this file <namespace>.dll.config and for it
to automally pull in the location of the dll: The files should be next
to each other in the same directory. However, if I do
xmlDoc.Load("<namespace>.dll.config") it automatically pulls in the
directory path to my test console app which I am using to test my class
library.

Basically I need to find a way of being able to call .Load() and pull
in the location of the current executing dll....not sure if this is
possible.

I am really trying to avoid hard coding the location of the Xml
file.....yuck

Cheers,

Olly
 
G

Guest

If I understand your question correctly, you probably want to look at the
Assembly.GetExecutingAssembly() method in the System.Reflection namespace,
which returns you the current assembly from which this method is called. Then
you can access the Name and other properties of this to get what you want for
your config filename.
Peter
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,

I have a similar situation here, I wrote a plugin for ArcGIS and of course
there is no exe involved, just a .dll . What I did was creating a file with
the same name than the dll and saved it in ApplicationData:

System.Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

You can then use reflection to get the assembly name :

Assembly.GetExecutingAssembly().GetName().FullName


Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top